import*as e from"../../core/common/common.js";import*as t from"../../core/platform/platform.js";import{assertNotNullOrUndefined as o}from"../../core/platform/platform.js";import*as r from"../../core/sdk/sdk.js";import*as s from"../text_utils/text_utils.js";import*as i from"../workspace/workspace.js";import*as n from"../../core/i18n/i18n.js";import*as a from"../../core/root/root.js";const c={unknownErrorLoadingFile:"Unknown error loading file"},u=n.i18n.registerUIStrings("models/bindings/ContentProviderBasedProject.ts",c),l=n.i18n.getLocalizedString.bind(void 0,u);class d extends i.Workspace.ProjectStore{#e;#t;constructor(e,t,o,r,s){super(e,t,o,r),this.#e=s,this.#t=new WeakMap,e.addProject(this)}async requestFileContent(e){const{contentProvider:t}=this.#t.get(e);try{const e=await t.requestContent();if("error"in e)return{error:e.error,isEncoded:e.isEncoded,content:null};const o="wasmDisassemblyInfo"in e?e.wasmDisassemblyInfo:void 0;return o&&!1===e.isEncoded?{content:"",wasmDisassemblyInfo:o,isEncoded:!1}:{content:e.content,isEncoded:e.isEncoded}}catch(e){return{content:null,isEncoded:!1,error:e?String(e):l(c.unknownErrorLoadingFile)}}}isServiceProject(){return this.#e}async requestMetadata(e){const{metadata:t}=this.#t.get(e);return t}canSetFileContent(){return!1}async setFileContent(e,t,o){}fullDisplayName(e){let t=e.parentURL().replace(/^(?:https?|file)\:\/\//,"");try{t=decodeURI(t)}catch(e){}return t+"/"+e.displayName(!0)}mimeType(e){const{mimeType:t}=this.#t.get(e);return t}canRename(){return!1}rename(e,t,o){const r=e.url();this.performRename(r,t,((t,r)=>{t&&r&&this.renameUISourceCode(e,r),o(t,r)}))}excludeFolder(e){}canExcludeFolder(e){return!1}async createFile(e,t,o,r){return null}canCreateFile(){return!1}deleteFile(e){}remove(){}performRename(e,t,o){o(!1)}searchInFileContent(e,t,o,r){const{contentProvider:s}=this.#t.get(e);return s.searchInContent(t,o,r)}async findFilesMatchingSearchRequest(e,t,o){const r=[];return o.setTotalWork(t.length),await Promise.all(t.map(async function(t){const s=this.uiSourceCodeForURL(t);if(s){let o=!0;for(const t of e.queries().slice()){if(!(await this.searchInFileContent(s,t,!e.ignoreCase(),e.isRegex())).length){o=!1;break}}o&&r.push(t)}o.incrementWorked(1)}.bind(this))),o.done(),r}indexContent(e){queueMicrotask(e.done.bind(e))}addUISourceCodeWithProvider(e,t,o,r){this.#t.set(e,{mimeType:r,metadata:o,contentProvider:t}),this.addUISourceCode(e)}addContentProvider(e,t,o){const r=this.createUISourceCode(e,t.contentType());return this.addUISourceCodeWithProvider(r,t,null,o),r}reset(){this.removeProject(),this.workspace().addProject(this)}dispose(){this.removeProject()}}var g=Object.freeze({__proto__:null,ContentProviderBasedProject:d});const p={removeFromIgnoreList:"Remove from ignore list",addScriptToIgnoreList:"Add script to ignore list",addDirectoryToIgnoreList:"Add directory to ignore list",addAllContentScriptsToIgnoreList:"Add all extension scripts to ignore list",addAllThirdPartyScriptsToIgnoreList:"Add all third-party scripts to ignore list"},h=n.i18n.registerUIStrings("models/bindings/IgnoreListManager.ts",p),m=n.i18n.getLocalizedString.bind(void 0,h);let S;class L{#o;#r;#s;constructor(t){this.#o=t,r.TargetManager.TargetManager.instance().addModelListener(r.DebuggerModel.DebuggerModel,r.DebuggerModel.Events.GlobalObjectCleared,this.clearCacheIfNeeded.bind(this),this),e.Settings.Settings.instance().moduleSetting("skipStackFramesPattern").addChangeListener(this.patternChanged.bind(this)),e.Settings.Settings.instance().moduleSetting("skipContentScripts").addChangeListener(this.patternChanged.bind(this)),e.Settings.Settings.instance().moduleSetting("automaticallyIgnoreListKnownThirdPartyScripts").addChangeListener(this.patternChanged.bind(this)),e.Settings.Settings.instance().moduleSetting("enableIgnoreListing").addChangeListener(this.patternChanged.bind(this)),this.#r=new Set,this.#s=new Map,r.TargetManager.TargetManager.instance().observeModels(r.DebuggerModel.DebuggerModel,this)}static instance(e={forceNew:null,debuggerWorkspaceBinding:null}){const{forceNew:t,debuggerWorkspaceBinding:o}=e;if(!S||t){if(!o)throw new Error(`Unable to create settings: debuggerWorkspaceBinding must be provided: ${(new Error).stack}`);S=new L(o)}return S}static removeInstance(){S=void 0}addChangeListener(e){this.#r.add(e)}removeChangeListener(e){this.#r.delete(e)}modelAdded(e){this.setIgnoreListPatterns(e);const t=e.sourceMapManager();t.addEventListener(r.SourceMapManager.Events.SourceMapAttached,this.sourceMapAttached,this),t.addEventListener(r.SourceMapManager.Events.SourceMapDetached,this.sourceMapDetached,this)}modelRemoved(e){this.clearCacheIfNeeded();const t=e.sourceMapManager();t.removeEventListener(r.SourceMapManager.Events.SourceMapAttached,this.sourceMapAttached,this),t.removeEventListener(r.SourceMapManager.Events.SourceMapDetached,this.sourceMapDetached,this)}clearCacheIfNeeded(){this.#s.size>1024&&this.#s.clear()}getSkipStackFramesPatternSetting(){return e.Settings.Settings.instance().moduleSetting("skipStackFramesPattern")}setIgnoreListPatterns(e){const t=this.enableIgnoreListing?this.getSkipStackFramesPatternSetting().getAsArray():[],o=[];for(const e of t)!e.disabled&&e.pattern&&o.push(e.pattern);return e.setBlackboxPatterns(o)}isUserOrSourceMapIgnoreListedUISourceCode(e){const t=e.project().type()===i.Workspace.projectTypes.ContentScripts;if(this.skipContentScripts&&t)return!0;if(e.isUnconditionallyIgnoreListed())return!0;const o=this.uiSourceCodeURL(e);return!!o&&this.isUserOrSourceMapIgnoreListedURL(o,e.isKnownThirdParty())}isUserOrSourceMapIgnoreListedURL(e,t){return!!this.isUserIgnoreListedURL(e)||!(!this.automaticallyIgnoreListKnownThirdPartyScripts||!t)}isUserIgnoreListedURL(e,t){if(!this.enableIgnoreListing)return!1;if(this.#s.has(e))return Boolean(this.#s.get(e));if(t&&this.skipContentScripts)return!0;const o=this.getSkipStackFramesPatternSetting().asRegExp(),r=o&&o.test(e)||!1;return this.#s.set(e,r),r}sourceMapAttached(e){const t=e.data.client,o=e.data.sourceMap;this.updateScriptRanges(t,o)}sourceMapDetached(e){const t=e.data.client;this.updateScriptRanges(t,void 0)}async updateScriptRanges(e,t){let o=!1;if(L.instance().isUserIgnoreListedURL(e.sourceURL,e.isContentScript())||(o=t?.sourceURLs().some((e=>this.isUserOrSourceMapIgnoreListedURL(e,t.hasIgnoreListHint(e))))??!1),!o)return M.get(e)&&await e.setBlackboxedRanges([])&&M.delete(e),void await this.#o.updateLocations(e);if(!t)return;const r=t.findRanges((e=>this.isUserOrSourceMapIgnoreListedURL(e,t.hasIgnoreListHint(e))),{isStartMatching:!0}).flatMap((e=>[e.start,e.end]));!function(e,t){if(e.length!==t.length)return!1;for(let o=0;o<e.length;++o)if(e[o].lineNumber!==t[o].lineNumber||e[o].columnNumber!==t[o].columnNumber)return!1;return!0}(M.get(e)||[],r)&&await e.setBlackboxedRanges(r)&&M.set(e,r),this.#o.updateLocations(e)}uiSourceCodeURL(e){return e.project().type()===i.Workspace.projectTypes.Debugger?null:e.url()}canIgnoreListUISourceCode(e){const t=this.uiSourceCodeURL(e);return!!t&&Boolean(this.urlToRegExpString(t))}ignoreListUISourceCode(e){const t=this.uiSourceCodeURL(e);t&&this.ignoreListURL(t)}unIgnoreListUISourceCode(e){e.project().type()===i.Workspace.projectTypes.ContentScripts&&this.unIgnoreListContentScripts(),e.isKnownThirdParty()&&this.unIgnoreListThirdParty();const t=this.uiSourceCodeURL(e);t&&this.unIgnoreListURL(t)}get enableIgnoreListing(){return e.Settings.Settings.instance().moduleSetting("enableIgnoreListing").get()}set enableIgnoreListing(t){e.Settings.Settings.instance().moduleSetting("enableIgnoreListing").set(t)}get skipContentScripts(){return this.enableIgnoreListing&&e.Settings.Settings.instance().moduleSetting("skipContentScripts").get()}get automaticallyIgnoreListKnownThirdPartyScripts(){return this.enableIgnoreListing&&e.Settings.Settings.instance().moduleSetting("automaticallyIgnoreListKnownThirdPartyScripts").get()}ignoreListContentScripts(){this.enableIgnoreListing||(this.enableIgnoreListing=!0),e.Settings.Settings.instance().moduleSetting("skipContentScripts").set(!0)}unIgnoreListContentScripts(){e.Settings.Settings.instance().moduleSetting("skipContentScripts").set(!1)}ignoreListThirdParty(){this.enableIgnoreListing||(this.enableIgnoreListing=!0),e.Settings.Settings.instance().moduleSetting("automaticallyIgnoreListKnownThirdPartyScripts").set(!0)}unIgnoreListThirdParty(){e.Settings.Settings.instance().moduleSetting("automaticallyIgnoreListKnownThirdPartyScripts").set(!1)}ignoreListURL(e){const t=this.urlToRegExpString(e);t&&this.ignoreListRegex(t,e)}ignoreListRegex(e,t){const o=this.getSkipStackFramesPatternSetting().getAsArray();let r=!1;for(let s=0;s<o.length;++s){const i=o[s];(i.pattern===e||t&&i.disabledForUrl===t)&&(i.disabled=!1,i.disabledForUrl=void 0,r=!0)}r||o.push({pattern:e,disabled:!1}),this.enableIgnoreListing||(this.enableIgnoreListing=!0),this.getSkipStackFramesPatternSetting().setAsArray(o)}unIgnoreListURL(e){let t=this.getSkipStackFramesPatternSetting().getAsArray();const o=L.instance().urlToRegExpString(e);if(o){t=t.filter((function(e){return e.pattern!==o}));for(let o=0;o<t.length;++o){const r=t[o];if(!r.disabled)try{new RegExp(r.pattern).test(e)&&(r.disabled=!0,r.disabledForUrl=e)}catch(e){}}this.getSkipStackFramesPatternSetting().setAsArray(t)}}removeIgnoreListPattern(e){let t=this.getSkipStackFramesPatternSetting().getAsArray();t=t.filter((function(t){return t.pattern!==e})),this.getSkipStackFramesPatternSetting().setAsArray(t)}ignoreListHasPattern(e,t){return this.getSkipStackFramesPatternSetting().getAsArray().some((o=>!(t&&o.disabled)&&o.pattern===e))}async patternChanged(){this.#s.clear();const e=[];for(const t of r.TargetManager.TargetManager.instance().models(r.DebuggerModel.DebuggerModel)){e.push(this.setIgnoreListPatterns(t));const o=t.sourceMapManager();for(const r of t.scripts())e.push(this.updateScriptRanges(r,o.sourceMapForClient(r)))}await Promise.all(e);const t=Array.from(this.#r);for(const e of t)e();this.patternChangeFinishedForTests()}patternChangeFinishedForTests(){}urlToRegExpString(o){const r=new e.ParsedURL.ParsedURL(o);if(r.isAboutBlank()||r.isDataURL())return"";if(!r.isValid)return"^"+t.StringUtilities.escapeForRegExp(o)+"$";let s=r.lastPathComponent;if(s?s="/"+s:r.folderPathComponents&&(s=r.folderPathComponents+"/"),s||(s=r.host),!s)return"";const i=r.scheme;let n="";return i&&"http"!==i&&"https"!==i&&(n="^"+i+"://","chrome-extension"===i&&(n+=r.host+"\\b"),n+=".*"),n+t.StringUtilities.escapeForRegExp(s)+(o.endsWith(s)?"$":"\\b")}getIgnoreListURLContextMenuItems(e){if(e.project().type()===i.Workspace.projectTypes.FileSystem)return[];const t=[],o=this.canIgnoreListUISourceCode(e),r=this.isUserOrSourceMapIgnoreListedUISourceCode(e),s=e.project().type()===i.Workspace.projectTypes.ContentScripts,n=e.isKnownThirdParty();return r?(o||s||n)&&t.push({text:m(p.removeFromIgnoreList),callback:this.unIgnoreListUISourceCode.bind(this,e)}):(o&&t.push({text:m(p.addScriptToIgnoreList),callback:this.ignoreListUISourceCode.bind(this,e)}),s&&t.push({text:m(p.addAllContentScriptsToIgnoreList),callback:this.ignoreListContentScripts.bind(this)}),n&&t.push({text:m(p.addAllThirdPartyScriptsToIgnoreList),callback:this.ignoreListThirdParty.bind(this)})),t}getIgnoreListFolderContextMenuItems(e){const o=[],r="^"+t.StringUtilities.escapeForRegExp(e)+"/";return this.ignoreListHasPattern(r,!0)?o.push({text:m(p.removeFromIgnoreList),callback:this.removeIgnoreListPattern.bind(this,r)}):o.push({text:m(p.addDirectoryToIgnoreList),callback:this.ignoreListRegex.bind(this,r)}),o}}const M=new WeakMap;var f=Object.freeze({__proto__:null,IgnoreListManager:L});const b=new WeakMap,C=new WeakMap;let I;class v extends e.ObjectWrapper.ObjectWrapper{constructor(){super()}static instance({forceNew:e}={forceNew:!1}){return I&&!e||(I=new v),I}}var w;!function(e){e.FrameAttributionAdded="FrameAttributionAdded",e.FrameAttributionRemoved="FrameAttributionRemoved"}(w||(w={}));class T{static resolveFrame(e,t){const o=T.targetForUISourceCode(e),s=o&&o.model(r.ResourceTreeModel.ResourceTreeModel);return s?s.frameForId(t):null}static setInitialFrameAttribution(e,t){if(!t)return;const o=T.resolveFrame(e,t);if(!o)return;const r=new Map;r.set(t,{frame:o,count:1}),b.set(e,r)}static cloneInitialFrameAttribution(e,t){const o=b.get(e);if(!o)return;const r=new Map;for(const e of o.keys()){const t=o.get(e);void 0!==t&&r.set(e,{frame:t.frame,count:t.count})}b.set(t,r)}static addFrameAttribution(e,t){const o=T.resolveFrame(e,t);if(!o)return;const r=b.get(e);if(!r)return;const s=r.get(t)||{frame:o,count:0};if(s.count+=1,r.set(t,s),1!==s.count)return;const i={uiSourceCode:e,frame:o};v.instance().dispatchEventToListeners(w.FrameAttributionAdded,i)}static removeFrameAttribution(e,t){const o=b.get(e);if(!o)return;const r=o.get(t);if(console.assert(Boolean(r),"Failed to remove frame attribution for url: "+e.url()),!r)return;if(r.count-=1,r.count>0)return;o.delete(t);const s={uiSourceCode:e,frame:r.frame};v.instance().dispatchEventToListeners(w.FrameAttributionRemoved,s)}static targetForUISourceCode(e){return C.get(e.project())||null}static setTargetForProject(e,t){C.set(e,t)}static getTargetForProject(e){return C.get(e)||null}static framesForUISourceCode(e){const t=T.targetForUISourceCode(e),o=t&&t.model(r.ResourceTreeModel.ResourceTreeModel),s=b.get(e);if(!o||!s)return[];return Array.from(s.keys()).map((e=>o.frameForId(e))).filter((e=>Boolean(e)))}}var R=Object.freeze({__proto__:null,NetworkProjectManager:v,get Events(){return w},NetworkProject:T});class y{#i;#o;#n=new Map;#a;#c;#u=new Map;#l=new Map;#d=new t.MapUtilities.Multimap;constructor(e,t,o){this.#i=e.sourceMapManager(),this.#o=o,this.#a=new d(t,"jsSourceMaps:stub:"+e.target().id(),i.Workspace.projectTypes.Service,"",!0),this.#c=[this.#i.addEventListener(r.SourceMapManager.Events.SourceMapWillAttach,this.sourceMapWillAttach,this),this.#i.addEventListener(r.SourceMapManager.Events.SourceMapFailedToAttach,this.sourceMapFailedToAttach,this),this.#i.addEventListener(r.SourceMapManager.Events.SourceMapAttached,this.sourceMapAttached,this),this.#i.addEventListener(r.SourceMapManager.Events.SourceMapDetached,this.sourceMapDetached,this)]}addStubUISourceCode(t){const o=this.#a.addContentProvider(e.ParsedURL.ParsedURL.concatenate(t.sourceURL,":sourcemap"),s.StaticContentProvider.StaticContentProvider.fromString(t.sourceURL,e.ResourceType.resourceTypes.Script,"\n\n\n\n\n// Please wait a bit.\n// Compiled script is not shown while source map is being loaded!"),"text/javascript");this.#n.set(t,o)}removeStubUISourceCode(e){const t=this.#n.get(e);this.#n.delete(e),t&&this.#a.removeUISourceCode(t.url())}getLocationRangesForSameSourceLocation(e){const t=e.debuggerModel,o=e.script();if(!o)return[];const r=this.#i.sourceMapForClient(o);if(!r)return[];const{lineNumber:s,columnNumber:i}=o.rawLocationToRelativeLocation(e),n=r.findEntry(s,i);if(!n||!n.sourceURL)return[];const a=this.#l.get(r);if(!a)return[];const c=a.uiSourceCodeForURL(n.sourceURL);if(!c)return[];if(!this.#d.hasValue(c,r))return[];return r.findReverseRanges(n.sourceURL,n.sourceLineNumber,n.sourceColumnNumber).map((({startLine:e,startColumn:r,endLine:s,endColumn:i})=>{const n=o.relativeLocationToRawLocation({lineNumber:e,columnNumber:r}),a=o.relativeLocationToRawLocation({lineNumber:s,columnNumber:i});return{start:t.createRawLocation(o,n.lineNumber,n.columnNumber),end:t.createRawLocation(o,a.lineNumber,a.columnNumber)}}))}uiSourceCodeForURL(e,t){const o=t?i.Workspace.projectTypes.ContentScripts:i.Workspace.projectTypes.Network;for(const t of this.#u.values()){if(t.type()!==o)continue;const r=t.uiSourceCodeForURL(e);if(r)return r}return null}rawLocationToUILocation(e){const t=e.script();if(!t)return null;const{lineNumber:o,columnNumber:r}=t.rawLocationToRelativeLocation(e),s=this.#n.get(t);if(s)return new i.UISourceCode.UILocation(s,o,r);const n=this.#i.sourceMapForClient(t);if(!n)return null;const a=this.#l.get(n);if(!a)return null;const c=n.findEntry(o,r);if(!c||!c.sourceURL)return null;const u=a.uiSourceCodeForURL(c.sourceURL);return u&&this.#d.hasValue(u,n)?u.uiLocation(c.sourceLineNumber,c.sourceColumnNumber):null}uiLocationToRawLocations(e,t,o){const r=[];for(const s of this.#d.get(e)){const i=s.sourceLineMapping(e.url(),t,o);if(!i)continue;const n=this.#i.clientForSourceMap(s);if(!n)continue;const a=n.relativeLocationToRawLocation(i);r.push(n.debuggerModel.createRawLocation(n,a.lineNumber,a.columnNumber))}return r}uiLocationRangeToRawLocationRanges(e,t){if(!this.#d.has(e))return null;const o=[];for(const r of this.#d.get(e)){const s=this.#i.clientForSourceMap(r);if(s)for(const i of r.reverseMapTextRanges(e.url(),t)){const e=s.relativeLocationToRawLocation(i.start),t=s.relativeLocationToRawLocation(i.end),r=s.debuggerModel.createRawLocation(s,e.lineNumber,e.columnNumber),n=s.debuggerModel.createRawLocation(s,t.lineNumber,t.columnNumber);o.push({start:r,end:n})}}return o}getMappedLines(e){if(!this.#d.has(e))return null;const t=new Set;for(const o of this.#d.get(e))for(const r of o.mappings())r.sourceURL===e.url()&&t.add(r.sourceLineNumber);return t}sourceMapWillAttach(e){const{client:t}=e.data;this.addStubUISourceCode(t),this.#o.updateLocations(t)}sourceMapFailedToAttach(e){const{client:t}=e.data;this.removeStubUISourceCode(t),this.#o.updateLocations(t)}sourceMapAttached(t){const{client:o,sourceMap:n}=t.data,a=new Set([o]);if(this.removeStubUISourceCode(o),!L.instance().isUserIgnoreListedURL(o.sourceURL,o.isContentScript())){const t=o.target(),c=`jsSourceMaps:${o.isContentScript()?"extensions":""}:${t.id()}`;let u=this.#u.get(c);if(!u){const e=o.isContentScript()?i.Workspace.projectTypes.ContentScripts:i.Workspace.projectTypes.Network;u=new d(this.#a.workspace(),c,e,"",!1),T.setTargetForProject(u,t),this.#u.set(c,u)}this.#l.set(n,u);for(const t of n.sourceURLs()){const c=e.ResourceType.resourceTypes.SourceMapScript,l=u.createUISourceCode(t,c);n.hasIgnoreListHint(t)&&l.markKnownThirdParty();const d=n.embeddedContentByURL(t),g=null!==d?s.StaticContentProvider.StaticContentProvider.fromString(t,c,d):new r.CompilerSourceMappingContentProvider.CompilerSourceMappingContentProvider(t,c,o.createPageResourceLoadInitiator());let p=null;if(null!==d){const e=new TextEncoder;p=new i.UISourceCode.UISourceCodeMetadata(null,e.encode(d).length)}const h=e.ResourceType.ResourceType.mimeFromURL(t)??c.canonicalMimeType();this.#d.set(l,n),T.setInitialFrameAttribution(l,o.frameId);const m=u.uiSourceCodeForURL(t);if(null!==m){for(const e of this.#d.get(m)){this.#d.delete(m,e);const o=this.#i.clientForSourceMap(e);o&&(T.removeFrameAttribution(m,o.frameId),n.compatibleForURL(t,e)&&(this.#d.set(l,e),T.addFrameAttribution(l,o.frameId)),a.add(o))}u.removeUISourceCode(t)}u.addUISourceCodeWithProvider(l,g,p,h)}}Promise.all([...a].map((e=>this.#o.updateLocations(e)))).then((()=>this.sourceMapAttachedForTest(n)))}sourceMapDetached(e){const{client:t,sourceMap:o}=e.data,r=this.#l.get(o);if(r){for(const e of r.uiSourceCodes())this.#d.delete(e,o)&&(T.removeFrameAttribution(e,t.frameId),this.#d.has(e)||r.removeUISourceCode(e.url()));this.#l.delete(o),this.#o.updateLocations(t)}}scriptsForUISourceCode(e){const t=[];for(const o of this.#d.get(e)){const e=this.#i.clientForSourceMap(o);e&&t.push(e)}return t}sourceMapAttachedForTest(e){}dispose(){e.EventTarget.removeEventListeners(this.#c);for(const e of this.#u.values())e.dispose();this.#a.dispose()}}var F=Object.freeze({__proto__:null,CompilerScriptMapping:y});class U{#g;#p;#h;constructor(e,t){this.#g=e,this.#p=t,this.#p.add(this),this.#h=null}async update(){this.#g&&(this.#h?await this.#h.then((()=>this.update())):(this.#h=this.#g(this),await this.#h,this.#h=null))}async uiLocation(){throw"Not implemented"}dispose(){this.#p.delete(this),this.#g=null}isDisposed(){return!this.#p.has(this)}async isIgnoreListed(){throw"Not implemented"}}class P{#m;constructor(){this.#m=new Set}add(e){this.#m.add(e)}delete(e){this.#m.delete(e)}has(e){return this.#m.has(e)}disposeAll(){for(const e of this.#m)e.dispose()}}var k=Object.freeze({__proto__:null,LiveLocationWithPool:U,LiveLocationPool:P});class j{#i;#S;#c;#L;constructor(e,t,o){this.#i=t,this.#S=new d(o,"cssSourceMaps:"+e.id(),i.Workspace.projectTypes.Network,"",!1),T.setTargetForProject(this.#S,e),this.#L=new Map,this.#c=[this.#i.addEventListener(r.SourceMapManager.Events.SourceMapAttached,this.sourceMapAttached,this),this.#i.addEventListener(r.SourceMapManager.Events.SourceMapDetached,this.sourceMapDetached,this)]}sourceMapAttachedForTest(e){}async sourceMapAttached(e){const t=e.data.client,o=e.data.sourceMap,r=this.#S,s=this.#L;for(const e of o.sourceURLs()){let i=s.get(e);i||(i=new E(r,e,t.createPageResourceLoadInitiator()),s.set(e,i)),i.addSourceMap(o,t.frameId)}await q.instance().updateLocations(t),this.sourceMapAttachedForTest(o)}async sourceMapDetached(e){const t=e.data.client,o=e.data.sourceMap,r=this.#L;for(const e of o.sourceURLs()){const s=r.get(e);s&&(s.removeSourceMap(o,t.frameId),s.getUiSourceCode()||r.delete(e))}await q.instance().updateLocations(t)}rawLocationToUILocation(e){const t=e.header();if(!t)return null;const o=this.#i.sourceMapForClient(t);if(!o)return null;let{lineNumber:r,columnNumber:s}=e;o.mapsOrigin()&&t.isInline&&(r-=t.startLine,0===r&&(s-=t.startColumn));const i=o.findEntry(r,s);if(!i||!i.sourceURL)return null;const n=this.#S.uiSourceCodeForURL(i.sourceURL);return n?n.uiLocation(i.sourceLineNumber,i.sourceColumnNumber):null}uiLocationToRawLocations(e){const{uiSourceCode:t,lineNumber:o,columnNumber:s=0}=e,i=D.get(t);if(!i)return[];const n=[];for(const e of i.getReferringSourceMaps()){const i=e.findReverseEntries(t.url(),o,s),a=this.#i.clientForSourceMap(e);a&&n.push(...i.map((e=>new r.CSSModel.CSSLocation(a,e.lineNumber,e.columnNumber))))}return n}static uiSourceOrigin(e){const t=D.get(e);return t?t.getReferringSourceMaps().map((e=>e.compiledURL())):[]}dispose(){e.EventTarget.removeEventListeners(this.#c),this.#S.dispose()}}const D=new WeakMap;class E{#S;#M;#f;referringSourceMaps;uiSourceCode;constructor(e,t,o){this.#S=e,this.#M=t,this.#f=o,this.referringSourceMaps=[],this.uiSourceCode=null}recreateUISourceCodeIfNeeded(t){const o=this.referringSourceMaps[this.referringSourceMaps.length-1],n=e.ResourceType.resourceTypes.SourceMapStyleSheet,a=o.embeddedContentByURL(this.#M),c=null!==a?s.StaticContentProvider.StaticContentProvider.fromString(this.#M,n,a):new r.CompilerSourceMappingContentProvider.CompilerSourceMappingContentProvider(this.#M,n,this.#f),u=this.#S.createUISourceCode(this.#M,n);D.set(u,this);const l=e.ResourceType.ResourceType.mimeFromURL(this.#M)||n.canonicalMimeType(),d="string"==typeof a?new i.UISourceCode.UISourceCodeMetadata(null,a.length):null;this.uiSourceCode?(T.cloneInitialFrameAttribution(this.uiSourceCode,u),this.#S.removeUISourceCode(this.uiSourceCode.url())):T.setInitialFrameAttribution(u,t),this.uiSourceCode=u,this.#S.addUISourceCodeWithProvider(this.uiSourceCode,c,d,l)}addSourceMap(e,t){this.uiSourceCode&&T.addFrameAttribution(this.uiSourceCode,t),this.referringSourceMaps.push(e),this.recreateUISourceCodeIfNeeded(t)}removeSourceMap(e,t){const o=this.uiSourceCode;T.removeFrameAttribution(o,t);const r=this.referringSourceMaps.lastIndexOf(e);-1!==r&&this.referringSourceMaps.splice(r,1),this.referringSourceMaps.length?this.recreateUISourceCodeIfNeeded(t):(this.#S.removeUISourceCode(o.url()),this.uiSourceCode=null)}getReferringSourceMaps(){return this.referringSourceMaps}getUiSourceCode(){return this.uiSourceCode}}var N=Object.freeze({__proto__:null,SASSSourceMapping:j});function A(e){for(const t of r.TargetManager.TargetManager.instance().models(r.ResourceTreeModel.ResourceTreeModel)){const o=t.resourceForURL(e);if(o)return o}return null}function x(e,t,o){const s=e.model(r.ResourceTreeModel.ResourceTreeModel);if(!s)return null;const i=s.frameForId(t);return i?O(i.resourceForURL(o)):null}function O(e){return!e||"number"!=typeof e.contentSize()&&!e.lastModified()?null:new i.UISourceCode.UISourceCodeMetadata(e.lastModified(),e.contentSize())}var W=Object.freeze({__proto__:null,resourceForURL:A,displayNameForURL:function(o){if(!o)return"";const s=A(o);if(s)return s.displayName;const n=i.Workspace.WorkspaceImpl.instance().uiSourceCodeForURL(o);if(n)return n.displayName();const a=r.TargetManager.TargetManager.instance().inspectedURL();if(!a)return t.StringUtilities.trimURL(o,"");const c=e.ParsedURL.ParsedURL.fromString(a);if(!c)return o;const u=c.lastPathComponent,l=a.indexOf(u);if(-1!==l&&l+u.length===a.length){const e=a.substring(0,l);if(o.startsWith(e))return o.substring(l)}const d=t.StringUtilities.trimURL(o,c.host);return"/"===d?c.host+"/":d},metadataForURL:x,resourceMetadata:O});const B=new WeakMap;class H{#b;#S;#C;#c;constructor(e,t){this.#b=e;const o=this.#b.target();this.#S=new d(t,"css:"+o.id(),i.Workspace.projectTypes.Network,"",!1),T.setTargetForProject(this.#S,o),this.#C=new Map,this.#c=[this.#b.addEventListener(r.CSSModel.Events.StyleSheetAdded,this.styleSheetAdded,this),this.#b.addEventListener(r.CSSModel.Events.StyleSheetRemoved,this.styleSheetRemoved,this),this.#b.addEventListener(r.CSSModel.Events.StyleSheetChanged,this.styleSheetChanged,this)]}rawLocationToUILocation(e){const t=e.header();if(!t||!this.acceptsHeader(t))return null;const o=this.#C.get(t.resourceURL());if(!o)return null;let r=e.lineNumber,s=e.columnNumber;if(t.isInline&&t.hasSourceURL){r-=t.lineNumberInSource(0);const e=t.columnNumberInSource(r,0);void 0===e?s=e:s-=e}return o.getUiSourceCode().uiLocation(r,s)}uiLocationToRawLocations(e){const t=B.get(e.uiSourceCode);if(!t)return[];const o=[];for(const s of t.getHeaders()){let t=e.lineNumber,i=e.columnNumber;s.isInline&&s.hasSourceURL&&(i=s.columnNumberInSource(t,e.columnNumber||0),t=s.lineNumberInSource(t)),o.push(new r.CSSModel.CSSLocation(s,t,i))}return o}acceptsHeader(e){return!e.isConstructedByNew()&&(!(e.isInline&&!e.hasSourceURL&&"inspector"!==e.origin)&&!!e.resourceURL())}styleSheetAdded(e){const t=e.data;if(!this.acceptsHeader(t))return;const o=t.resourceURL();let r=this.#C.get(o);r?r.addHeader(t):(r=new _(this.#b,this.#S,t),this.#C.set(o,r))}styleSheetRemoved(e){const t=e.data;if(!this.acceptsHeader(t))return;const o=t.resourceURL(),r=this.#C.get(o);r&&(1===r.getHeaders().size?(r.dispose(),this.#C.delete(o)):r.removeHeader(t))}styleSheetChanged(e){const t=this.#b.styleSheetHeaderForId(e.data.styleSheetId);if(!t||!this.acceptsHeader(t))return;const o=this.#C.get(t.resourceURL());o&&o.styleSheetChanged(t)}dispose(){for(const e of this.#C.values())e.dispose();this.#C.clear(),e.EventTarget.removeEventListeners(this.#c),this.#S.removeProject()}}class _{#b;#S;headers;uiSourceCode;#c;#I;#v;#w;#T;constructor(t,o,r){this.#b=t,this.#S=o,this.headers=new Set([r]);const s=t.target(),n=r.resourceURL(),a=x(s,r.frameId,n);this.uiSourceCode=this.#S.createUISourceCode(n,r.contentType()),B.set(this.uiSourceCode,this),T.setInitialFrameAttribution(this.uiSourceCode,r.frameId),this.#S.addUISourceCodeWithProvider(this.uiSourceCode,this,a,"text/css"),this.#c=[this.uiSourceCode.addEventListener(i.UISourceCode.Events.WorkingCopyChanged,this.workingCopyChanged,this),this.uiSourceCode.addEventListener(i.UISourceCode.Events.WorkingCopyCommitted,this.workingCopyCommitted,this)],this.#I=new e.Throttler.Throttler(_.updateTimeout),this.#v=!1}addHeader(e){this.headers.add(e),T.addFrameAttribution(this.uiSourceCode,e.frameId)}removeHeader(e){this.headers.delete(e),T.removeFrameAttribution(this.uiSourceCode,e.frameId)}styleSheetChanged(e){if(console.assert(this.headers.has(e)),this.#T||!this.headers.has(e))return;const t=this.mirrorContent.bind(this,e,!0);this.#I.schedule(t,!1)}workingCopyCommitted(){if(this.#w)return;const e=this.mirrorContent.bind(this,this.uiSourceCode,!0);this.#I.schedule(e,!0)}workingCopyChanged(){if(this.#w)return;const e=this.mirrorContent.bind(this,this.uiSourceCode,!1);this.#I.schedule(e,!1)}async mirrorContent(e,t){if(this.#v)return void this.styleFileSyncedForTest();let o=null;if(e===this.uiSourceCode)o=this.uiSourceCode.workingCopy();else{o=(await e.requestContent()).content}if(null===o||this.#v)return void this.styleFileSyncedForTest();e!==this.uiSourceCode&&(this.#w=!0,this.uiSourceCode.addRevision(o),this.#w=!1),this.#T=!0;const r=[];for(const s of this.headers)s!==e&&r.push(this.#b.setStyleSheetText(s.id,o,t));await Promise.all(r),this.#T=!1,this.styleFileSyncedForTest()}styleFileSyncedForTest(){}dispose(){this.#v||(this.#v=!0,this.#S.removeUISourceCode(this.uiSourceCode.url()),e.EventTarget.removeEventListeners(this.#c))}contentURL(){return console.assert(this.headers.size>0),this.headers.values().next().value.originalContentProvider().contentURL()}contentType(){return console.assert(this.headers.size>0),this.headers.values().next().value.originalContentProvider().contentType()}requestContent(){return console.assert(this.headers.size>0),this.headers.values().next().value.originalContentProvider().requestContent()}searchInContent(e,t,o){return console.assert(this.headers.size>0),this.headers.values().next().value.originalContentProvider().searchInContent(e,t,o)}static updateTimeout=200;getHeaders(){return this.headers}getUiSourceCode(){return this.uiSourceCode}}var z=Object.freeze({__proto__:null,StylesSourceMapping:H,StyleFile:_});let V;class q{#R;#y;#F;constructor(e,t){this.#R=e,this.#y=new Map,t.observeModels(r.CSSModel.CSSModel,this),this.#F=new Set}static instance(e={forceNew:null,resourceMapping:null,targetManager:null}){const{forceNew:t,resourceMapping:o,targetManager:r}=e;if(!V||t){if(!o||!r)throw new Error(`Unable to create CSSWorkspaceBinding: resourceMapping and targetManager must be provided: ${(new Error).stack}`);V=new q(o,r)}return V}static removeInstance(){V=void 0}get modelToInfo(){return this.#y}getCSSModelInfo(e){return this.#y.get(e)}modelAdded(e){this.#y.set(e,new J(e,this.#R))}modelRemoved(e){this.getCSSModelInfo(e).dispose(),this.#y.delete(e)}async pendingLiveLocationChangesPromise(){await Promise.all(this.#F)}recordLiveLocationChange(e){e.then((()=>{this.#F.delete(e)})),this.#F.add(e)}async updateLocations(e){const t=this.getCSSModelInfo(e.cssModel()).updateLocations(e);this.recordLiveLocationChange(t),await t}createLiveLocation(e,t,o){const r=this.getCSSModelInfo(e.cssModel()).createLiveLocation(e,t,o);return this.recordLiveLocationChange(r),r}propertyRawLocation(e,t){const o=e.ownerStyle;if(!o||o.type!==r.CSSStyleDeclaration.Type.Regular||!o.styleSheetId)return null;const s=o.cssModel().styleSheetHeaderForId(o.styleSheetId);if(!s)return null;const i=t?e.nameRange():e.valueRange();if(!i)return null;const n=i.startLine,a=i.startColumn;return new r.CSSModel.CSSLocation(s,s.lineNumberInSource(n),s.columnNumberInSource(n,a))}propertyUILocation(e,t){const o=this.propertyRawLocation(e,t);return o?this.rawLocationToUILocation(o):null}rawLocationToUILocation(e){return this.getCSSModelInfo(e.cssModel()).rawLocationToUILocation(e)}uiLocationToRawLocations(e){const t=[];for(const o of this.#y.values())t.push(...o.uiLocationToRawLocations(e));return t}}class J{#c;#R;#U;#P;#m;#k;constructor(e,o){this.#c=[e.addEventListener(r.CSSModel.Events.StyleSheetAdded,(e=>{this.styleSheetAdded(e)}),this),e.addEventListener(r.CSSModel.Events.StyleSheetRemoved,(e=>{this.styleSheetRemoved(e)}),this)],this.#R=o,this.#U=new H(e,o.workspace);const s=e.sourceMapManager();this.#P=new j(e.target(),s,o.workspace),this.#m=new t.MapUtilities.Multimap,this.#k=new t.MapUtilities.Multimap}get locations(){return this.#m}async createLiveLocation(e,t,o){const r=new K(e,this,t,o),s=e.header();return s?(r.setHeader(s),this.#m.set(s,r),await r.update()):this.#k.set(e.url,r),r}disposeLocation(e){const t=e.header();t?this.#m.delete(t,e):this.#k.delete(e.url,e)}updateLocations(e){const t=[];for(const o of this.#m.get(e))t.push(o.update());return Promise.all(t)}async styleSheetAdded(e){const t=e.data;if(!t.sourceURL)return;const o=[];for(const e of this.#k.get(t.sourceURL))e.setHeader(t),this.#m.set(t,e),o.push(e.update());await Promise.all(o),this.#k.deleteAll(t.sourceURL)}async styleSheetRemoved(e){const t=e.data,o=[];for(const e of this.#m.get(t))e.setHeader(t),this.#k.set(e.url,e),o.push(e.update());await Promise.all(o),this.#m.deleteAll(t)}rawLocationToUILocation(e){let t=null;return t=t||this.#P.rawLocationToUILocation(e),t=t||this.#U.rawLocationToUILocation(e),t=t||this.#R.cssLocationToUILocation(e),t}uiLocationToRawLocations(e){let t=this.#P.uiLocationToRawLocations(e);return t.length?t:(t=this.#U.uiLocationToRawLocations(e),t.length?t:this.#R.uiLocationToCSSLocations(e))}dispose(){e.EventTarget.removeEventListeners(this.#c),this.#U.dispose(),this.#P.dispose()}}class K extends U{url;#j;#D;#E;headerInternal;constructor(e,t,o,r){super(o,r),this.url=e.url,this.#j=e.lineNumber,this.#D=e.columnNumber,this.#E=t,this.headerInternal=null}header(){return this.headerInternal}setHeader(e){this.headerInternal=e}async uiLocation(){if(!this.headerInternal)return null;const e=new r.CSSModel.CSSLocation(this.headerInternal,this.#j,this.#D);return q.instance().rawLocationToUILocation(e)}dispose(){super.dispose(),this.#E.disposeLocation(this)}async isIgnoreListed(){return!1}}var G=Object.freeze({__proto__:null,CSSWorkspaceBinding:q,ModelInfo:J,LiveLocation:K});const $={errorInDebuggerLanguagePlugin:"Error in debugger language plugin: {PH1}",loadingDebugSymbolsForVia:"[{PH1}] Loading debug symbols for {PH2} (via {PH3})...",loadingDebugSymbolsFor:"[{PH1}] Loading debug symbols for {PH2}...",loadedDebugSymbolsForButDidnt:"[{PH1}] Loaded debug symbols for {PH2}, but didn't find any source files",loadedDebugSymbolsForFound:"[{PH1}] Loaded debug symbols for {PH2}, found {PH3} source file(s)",failedToLoadDebugSymbolsFor:"[{PH1}] Failed to load debug symbols for {PH2} ({PH3})",failedToLoadDebugSymbolsForFunction:'No debug information for function "{PH1}"',debugSymbolsIncomplete:"The debug information for function {PH1} is incomplete"},Q=n.i18n.registerUIStrings("models/bindings/DebuggerLanguagePlugins.ts",$),X=n.i18n.getLocalizedString.bind(void 0,Q);function Y(e){return`${e.sourceURL}@${e.hash}`}function Z(e){const{script:t}=e;return{rawModuleId:Y(t),codeOffset:e.location().columnNumber-(t.codeOffset()||0),inlineFrameIndex:e.inlineFrameIndex}}class ee extends Error{exception;exceptionDetails;constructor(e,t){const{description:o}=t.exception||{};super(o||t.text),this.exception=e,this.exceptionDetails=t}static makeLocal(e,t){const o={type:"object",subtype:"error",description:t},r={text:"Uncaught",exceptionId:-1,columnNumber:0,lineNumber:0,exception:o},s=e.debuggerModel.runtimeModel().createRemoteObject(o);return new ee(s,r)}}class te extends r.RemoteObject.LocalJSONObject{constructor(e){super(e)}get description(){return this.type}get type(){return"namespace"}}class oe extends r.RemoteObject.RemoteObjectImpl{variables;#N;#A;stopId;constructor(e,t,o){super(e.debuggerModel.runtimeModel(),void 0,"object",void 0,null),this.variables=[],this.#N=e,this.#A=o,this.stopId=t}async doGetProperties(e,t,o){if(t)return{properties:[],internalProperties:[]};const s=[],i={};function n(e,t){return new r.RemoteObject.RemoteObjectProperty(e,t,!1,!1,!0,!1)}for(const e of this.variables){let t;try{const o=await this.#A.evaluate(e.name,Z(this.#N),this.stopId);t=o?new se(this.#N,o,this.#A):new r.RemoteObject.LocalJSONObject(void 0)}catch(e){console.warn(e),t=new r.RemoteObject.LocalJSONObject(void 0)}if(e.nestedName&&e.nestedName.length>1){let o=i;for(let t=0;t<e.nestedName.length-1;t++){const r=e.nestedName[t];let s=o[r];s||(s=new te({}),o[r]=s),o=s.value}o[e.nestedName[e.nestedName.length-1]]=t}else s.push(n(e.name,t))}for(const e in i)s.push(n(e,i[e]));return{properties:s,internalProperties:[]}}}class re{#x;#O;#W;#B;#H;#_;#z;constructor(e,t,o,r,s,i){if(s&&"data:"!==new URL(s).protocol)throw new Error("The icon must be a data:-URL");this.#x=e,this.#O=o,this.#W=r,this.#B=s,this.#H=new oe(e,t,i),this.#_=null,this.#z=null}async getVariableValue(e){for(let t=0;t<this.#H.variables.length;++t){if(this.#H.variables[t].name!==e)continue;const o=await this.#H.getAllProperties(!1,!1);if(!o.properties)continue;const{value:r}=o.properties[t];if(r)return r}return null}callFrame(){return this.#x}type(){return this.#O}typeName(){return this.#W}name(){}startLocation(){return this.#_}endLocation(){return this.#z}object(){return this.#H}description(){return""}icon(){return this.#B}}class se extends r.RemoteObject.RemoteObject{extensionObject;plugin;callFrame;constructor(e,t,o){super(),this.extensionObject=t,this.plugin=o,this.callFrame=e}get linearMemoryAddress(){return this.extensionObject.linearMemoryAddress}get linearMemorySize(){return this.extensionObject.linearMemorySize}get objectId(){return this.extensionObject.objectId}get type(){return"array"===this.extensionObject.type||"null"===this.extensionObject.type?"object":this.extensionObject.type}get subtype(){if("array"===this.extensionObject.type||"null"===this.extensionObject.type)return this.extensionObject.type}get value(){return this.extensionObject.value}unserializableValue(){}get description(){return this.extensionObject.description}set description(e){}get hasChildren(){return this.extensionObject.hasChildren}get preview(){}get className(){return this.extensionObject.className??null}arrayLength(){return 0}arrayBufferByteLength(){return 0}getOwnProperties(e,t){return this.getAllProperties(!1,e,t)}async getAllProperties(e,t,s){const{objectId:i}=this.extensionObject;if(i){o(this.plugin.getProperties);return{properties:(await this.plugin.getProperties(i)).map((e=>new r.RemoteObject.RemoteObjectProperty(e.name,new se(this.callFrame,e.value,this.plugin)))),internalProperties:null}}return{properties:null,internalProperties:null}}release(){const{objectId:e}=this.extensionObject;e&&(o(this.plugin.releaseObject),this.plugin.releaseObject(e))}debuggerModel(){return this.callFrame.debuggerModel}runtimeModel(){return this.callFrame.debuggerModel.runtimeModel()}}class ie{#V;#o;#q;#J;#K;callFrameByStopId=new Map;stopIdByCallFrame=new Map;nextStopId=0n;constructor(e,t,o){this.#V=t,this.#o=o,this.#q=[],this.#J=new Map,e.observeModels(r.DebuggerModel.DebuggerModel,this),this.#K=new Map}async evaluateOnCallFrame(e,t){const{script:o}=e,{expression:s,returnByValue:i,throwOnSideEffect:n}=t,{plugin:a}=await this.rawModuleIdAndPluginForScript(o);if(!a)return null;const c=Z(e);if(0===(await a.rawLocationToSourceLocation(c)).length)return null;if(i)return{error:"Cannot return by value"};if(n)return{error:"Cannot guarantee side-effect freedom"};try{const t=await a.evaluate(s,c,this.stopIdForCallFrame(e));return t?{object:new se(e,t,a),exceptionDetails:void 0}:{object:new r.RemoteObject.LocalJSONObject(void 0),exceptionDetails:void 0}}catch(t){if(t instanceof ee){const{exception:e,exceptionDetails:o}=t;return{object:e,exceptionDetails:o}}const{exception:o,exceptionDetails:r}=ee.makeLocal(e,t.message);return{object:o,exceptionDetails:r}}}stopIdForCallFrame(e){let t=this.stopIdByCallFrame.get(e);return void 0!==t||(t=this.nextStopId++,this.stopIdByCallFrame.set(e,t),this.callFrameByStopId.set(t,e)),t}callFrameForStopId(e){return this.callFrameByStopId.get(e)}expandCallFrames(e){return Promise.all(e.map((async e=>{const t=await this.getFunctionInfo(e.script,e.location());if(t){if("frames"in t&&t.frames.length)return t.frames.map((({name:t},o)=>e.createVirtualCallFrame(o,t)));if("missingSymbolFiles"in t&&t.missingSymbolFiles.length){const o=t.missingSymbolFiles,r=X($.debugSymbolsIncomplete,{PH1:e.functionName});e.setMissingDebugInfoDetails({details:r,resources:o})}else e.setMissingDebugInfoDetails({resources:[],details:X($.failedToLoadDebugSymbolsForFunction,{PH1:e.functionName})})}return e}))).then((e=>e.flat()))}modelAdded(e){this.#J.set(e,new ne(e,this.#V)),e.addEventListener(r.DebuggerModel.Events.GlobalObjectCleared,this.globalObjectCleared,this),e.addEventListener(r.DebuggerModel.Events.ParsedScriptSource,this.parsedScriptSource,this),e.addEventListener(r.DebuggerModel.Events.DebuggerResumed,this.debuggerResumed,this),e.setEvaluateOnCallFrameCallback(this.evaluateOnCallFrame.bind(this)),e.setExpandCallFramesCallback(this.expandCallFrames.bind(this))}modelRemoved(t){t.removeEventListener(r.DebuggerModel.Events.GlobalObjectCleared,this.globalObjectCleared,this),t.removeEventListener(r.DebuggerModel.Events.ParsedScriptSource,this.parsedScriptSource,this),t.removeEventListener(r.DebuggerModel.Events.DebuggerResumed,this.debuggerResumed,this),t.setEvaluateOnCallFrameCallback(null),t.setExpandCallFramesCallback(null);const o=this.#J.get(t);o&&(o.dispose(),this.#J.delete(t)),this.#K.forEach(((o,r)=>{const s=o.scripts.filter((e=>e.debuggerModel!==t));0===s.length?(o.plugin.removeRawModule(r).catch((t=>{e.Console.Console.instance().error(X($.errorInDebuggerLanguagePlugin,{PH1:t.message}))})),this.#K.delete(r)):o.scripts=s}))}globalObjectCleared(e){const t=e.data;this.modelRemoved(t),this.modelAdded(t)}addPlugin(e){this.#q.push(e);for(const e of this.#J.keys())for(const t of e.scripts())this.hasPluginForScript(t)||this.parsedScriptSource({data:t})}removePlugin(e){this.#q=this.#q.filter((t=>t!==e));const t=new Set;this.#K.forEach(((o,r)=>{o.plugin===e&&(o.scripts.forEach((e=>t.add(e))),this.#K.delete(r))}));for(const e of t){this.#J.get(e.debuggerModel).removeScript(e),this.parsedScriptSource({data:e})}}hasPluginForScript(e){const t=Y(e),o=this.#K.get(t);return void 0!==o&&o.scripts.includes(e)}async rawModuleIdAndPluginForScript(e){const t=Y(e),o=this.#K.get(t);return o&&(await o.addRawModulePromise,o===this.#K.get(t))?{rawModuleId:t,plugin:o.plugin}:{rawModuleId:t,plugin:null}}uiSourceCodeForURL(e,t){const o=this.#J.get(e);return o?o.getProject().uiSourceCodeForURL(t):null}async rawLocationToUILocation(t){const o=t.script();if(!o)return null;const{rawModuleId:r,plugin:s}=await this.rawModuleIdAndPluginForScript(o);if(!s)return null;const i={rawModuleId:r,codeOffset:t.columnNumber-(o.codeOffset()||0),inlineFrameIndex:t.inlineFrameIndex};try{const e=await s.rawLocationToSourceLocation(i);for(const t of e){const e=this.uiSourceCodeForURL(o.debuggerModel,t.sourceFileURL);if(e)return e.uiLocation(t.lineNumber,t.columnNumber>=0?t.columnNumber:void 0)}}catch(t){e.Console.Console.instance().error(X($.errorInDebuggerLanguagePlugin,{PH1:t.message}))}return null}uiLocationToRawLocationRanges(t,o,s=-1){const i=[];return this.scriptsForUISourceCode(t).forEach((e=>{const n=Y(e),a=this.#K.get(n);if(!a)return;const{plugin:c}=a;i.push(async function(e,i,n){const a={rawModuleId:e,sourceFileURL:t.url(),lineNumber:o,columnNumber:s},c=await i.sourceLocationToRawLocation(a);if(!c)return[];return c.map((e=>({start:new r.DebuggerModel.Location(n.debuggerModel,n.scriptId,0,Number(e.startOffset)+(n.codeOffset()||0)),end:new r.DebuggerModel.Location(n.debuggerModel,n.scriptId,0,Number(e.endOffset)+(n.codeOffset()||0))})))}(n,c,e))})),0===i.length?Promise.resolve(null):Promise.all(i).then((e=>e.flat())).catch((t=>(e.Console.Console.instance().error(X($.errorInDebuggerLanguagePlugin,{PH1:t.message})),null)))}async uiLocationToRawLocations(e,t,o){const r=await this.uiLocationToRawLocationRanges(e,t,o);return r?r.map((({start:e})=>e)):null}async uiLocationRangeToRawLocationRanges(e,t){const o=[];for(let r=t.startLine;r<=t.endLine;++r)o.push(this.uiLocationToRawLocationRanges(e,r));const r=[];for(const e of await Promise.all(o)){if(null===e)return null;for(const o of e){const[e,i]=await Promise.all([this.rawLocationToUILocation(o.start),this.rawLocationToUILocation(o.end)]);if(null===e||null===i)continue;t.intersection(new s.TextRange.TextRange(e.lineNumber,e.columnNumber??0,i.lineNumber,i.columnNumber??1/0)).isEmpty()||r.push(o)}}return r}scriptsForUISourceCode(e){for(const t of this.#J.values()){const o=t.uiSourceCodeToScripts.get(e);if(o)return o}return[]}setDebugInfoURL(e,t){this.hasPluginForScript(e)||(e.debugSymbols={type:"ExternalDWARF",externalURL:t},this.parsedScriptSource({data:e}),e.debuggerModel.setDebugInfoURL(e,t))}parsedScriptSource(t){const o=t.data;if(o.sourceURL)for(const t of this.#q){if(!t.handleScript(o))continue;const r=Y(o);let s=this.#K.get(r);if(s)s.scripts.push(o);else{const i=(async()=>{const i=e.Console.Console.instance(),n=o.sourceURL,a=o.debugSymbols&&o.debugSymbols.externalURL||"";a?i.log(X($.loadingDebugSymbolsForVia,{PH1:t.name,PH2:n,PH3:a})):i.log(X($.loadingDebugSymbolsFor,{PH1:t.name,PH2:n}));try{const e=!a&&n.startsWith("wasm://")?await o.getWasmBytecode():void 0,c=await t.addRawModule(r,a,{url:n,code:e});if(s!==this.#K.get(r))return[];if("missingSymbolFiles"in c)return{missingSymbolFiles:c.missingSymbolFiles};const u=c;return 0===u.length?i.warn(X($.loadedDebugSymbolsForButDidnt,{PH1:t.name,PH2:n})):i.log(X($.loadedDebugSymbolsForFound,{PH1:t.name,PH2:n,PH3:u.length})),u}catch(e){return i.error(X($.failedToLoadDebugSymbolsFor,{PH1:t.name,PH2:n,PH3:e.message})),this.#K.delete(r),[]}})();s={rawModuleId:r,plugin:t,scripts:[o],addRawModulePromise:i},this.#K.set(r,s)}return void s.addRawModulePromise.then((e=>{if(!("missingSymbolFiles"in e)&&o.debuggerModel.scriptForId(o.scriptId)===o){const t=this.#J.get(o.debuggerModel);t&&(t.addSourceFiles(o,e),this.#o.updateLocations(o))}}))}}debuggerResumed(e){const t=Array.from(this.callFrameByStopId.values()).filter((t=>t.debuggerModel===e.data));for(const e of t){const t=this.stopIdByCallFrame.get(e);o(t),this.stopIdByCallFrame.delete(e),this.callFrameByStopId.delete(t)}}getSourcesForScript(e){const t=Y(e),o=this.#K.get(t);return o?o.addRawModulePromise:Promise.resolve(void 0)}async resolveScopeChain(t){const o=t.script,{rawModuleId:r,plugin:s}=await this.rawModuleIdAndPluginForScript(o);if(!s)return null;const i={rawModuleId:r,codeOffset:t.location().columnNumber-(o.codeOffset()||0),inlineFrameIndex:t.inlineFrameIndex},n=this.stopIdForCallFrame(t);try{if(0===(await s.rawLocationToSourceLocation(i)).length)return null;const e=new Map,o=await s.listVariablesInScope(i);for(const r of o||[]){let o=e.get(r.scope);if(!o){const{type:i,typeName:a,icon:c}=await s.getScopeInfo(r.scope);o=new re(t,n,i,a,c,s),e.set(r.scope,o)}o.object().variables.push(r)}return Array.from(e.values())}catch(t){return e.Console.Console.instance().error(X($.errorInDebuggerLanguagePlugin,{PH1:t.message})),null}}async getFunctionInfo(t,o){const{rawModuleId:r,plugin:s}=await this.rawModuleIdAndPluginForScript(t);if(!s)return null;const i={rawModuleId:r,codeOffset:o.columnNumber-(t.codeOffset()||0),inlineFrameIndex:0};try{return await s.getFunctionInfo(i)}catch(t){return e.Console.Console.instance().warn(X($.errorInDebuggerLanguagePlugin,{PH1:t.message})),{frames:[]}}}async getInlinedFunctionRanges(t){const o=t.script();if(!o)return[];const{rawModuleId:s,plugin:i}=await this.rawModuleIdAndPluginForScript(o);if(!i)return[];const n={rawModuleId:s,codeOffset:t.columnNumber-(o.codeOffset()||0)};try{return(await i.getInlinedFunctionRanges(n)).map((e=>({start:new r.DebuggerModel.Location(o.debuggerModel,o.scriptId,0,Number(e.startOffset)+(o.codeOffset()||0)),end:new r.DebuggerModel.Location(o.debuggerModel,o.scriptId,0,Number(e.endOffset)+(o.codeOffset()||0))})))}catch(t){return e.Console.Console.instance().warn(X($.errorInDebuggerLanguagePlugin,{PH1:t.message})),[]}}async getInlinedCalleesRanges(t){const o=t.script();if(!o)return[];const{rawModuleId:s,plugin:i}=await this.rawModuleIdAndPluginForScript(o);if(!i)return[];const n={rawModuleId:s,codeOffset:t.columnNumber-(o.codeOffset()||0)};try{return(await i.getInlinedCalleesRanges(n)).map((e=>({start:new r.DebuggerModel.Location(o.debuggerModel,o.scriptId,0,Number(e.startOffset)+(o.codeOffset()||0)),end:new r.DebuggerModel.Location(o.debuggerModel,o.scriptId,0,Number(e.endOffset)+(o.codeOffset()||0))})))}catch(t){return e.Console.Console.instance().warn(X($.errorInDebuggerLanguagePlugin,{PH1:t.message})),[]}}async getMappedLines(e){const t=await Promise.all(this.scriptsForUISourceCode(e).map((e=>this.rawModuleIdAndPluginForScript(e))));let o=null;for(const{rawModuleId:r,plugin:s}of t){if(!s)continue;const t=await s.getMappedLines(r,e.url());void 0!==t&&(null===o?o=new Set(t):t.forEach((e=>o.add(e))))}return o}}class ne{project;uiSourceCodeToScripts;constructor(e,t){this.project=new d(t,"language_plugins::"+e.target().id(),i.Workspace.projectTypes.Network,"",!1),T.setTargetForProject(this.project,e.target()),this.uiSourceCodeToScripts=new Map}addSourceFiles(t,o){const s=t.createPageResourceLoadInitiator();for(const i of o){let o=this.project.uiSourceCodeForURL(i);if(o){const e=this.uiSourceCodeToScripts.get(o);e.includes(t)||e.push(t)}else{o=this.project.createUISourceCode(i,e.ResourceType.resourceTypes.SourceMapScript),T.setInitialFrameAttribution(o,t.frameId),this.uiSourceCodeToScripts.set(o,[t]);const n=new r.CompilerSourceMappingContentProvider.CompilerSourceMappingContentProvider(i,e.ResourceType.resourceTypes.SourceMapScript,s),a=e.ResourceType.ResourceType.mimeFromURL(i)||"text/javascript";this.project.addUISourceCodeWithProvider(o,n,null,a)}}}removeScript(e){this.uiSourceCodeToScripts.forEach(((t,o)=>{0===(t=t.filter((t=>t!==e))).length?(this.uiSourceCodeToScripts.delete(o),this.project.removeUISourceCode(o.url())):this.uiSourceCodeToScripts.set(o,t)}))}dispose(){this.project.dispose()}getProject(){return this.project}}var ae=Object.freeze({__proto__:null,SourceScope:re,ExtensionRemoteObject:se,DebuggerLanguagePluginManager:ie});class ce{#o;#S;#c;#G;#$;constructor(e,t,o){ue.add(this),this.#o=o,this.#S=new d(t,"debugger:"+e.target().id(),i.Workspace.projectTypes.Debugger,"",!0),this.#c=[e.addEventListener(r.DebuggerModel.Events.GlobalObjectCleared,this.globalObjectCleared,this),e.addEventListener(r.DebuggerModel.Events.ParsedScriptSource,this.parsedScriptSource,this),e.addEventListener(r.DebuggerModel.Events.DiscardedAnonymousScriptSource,this.discardedScriptSource,this)],this.#G=new Map,this.#$=new Map}static createV8ScriptURL(t){const o=e.ParsedURL.ParsedURL.extractName(t.sourceURL);return"debugger:///VM"+t.scriptId+(o?" "+o:"")}static scriptForUISourceCode(e){for(const t of ue){const o=t.#G.get(e);if(void 0!==o)return o}return null}uiSourceCodeForScript(e){return this.#$.get(e)??null}rawLocationToUILocation(e){const t=e.script();if(!t)return null;const o=this.#$.get(t);if(!o)return null;const{lineNumber:r,columnNumber:s}=t.rawLocationToRelativeLocation(e);return o.uiLocation(r,s)}uiLocationToRawLocations(e,t,o){const r=this.#G.get(e);return r?(({lineNumber:t,columnNumber:o}=r.relativeLocationToRawLocation({lineNumber:t,columnNumber:o})),[r.debuggerModel.createRawLocation(r,t,o??0)]):[]}uiLocationRangeToRawLocationRanges(e,{startLine:t,startColumn:o,endLine:r,endColumn:s}){const i=this.#G.get(e);if(!i)return[];({lineNumber:t,columnNumber:o}=i.relativeLocationToRawLocation({lineNumber:t,columnNumber:o})),({lineNumber:r,columnNumber:s}=i.relativeLocationToRawLocation({lineNumber:r,columnNumber:s}));return[{start:i.debuggerModel.createRawLocation(i,t,o),end:i.debuggerModel.createRawLocation(i,r,s)}]}parsedScriptSource(t){const o=t.data,r=ce.createV8ScriptURL(o),s=this.#S.createUISourceCode(r,e.ResourceType.resourceTypes.Script);o.isBreakpointCondition&&s.markAsUnconditionallyIgnoreListed(),this.#G.set(s,o),this.#$.set(o,s),this.#S.addUISourceCodeWithProvider(s,o,null,"text/javascript"),this.#o.updateLocations(o)}discardedScriptSource(e){const t=e.data,o=this.#$.get(t);void 0!==o&&(this.#$.delete(t),this.#G.delete(o),this.#S.removeUISourceCode(o.url()))}globalObjectCleared(){this.#$.clear(),this.#G.clear(),this.#S.reset()}dispose(){ue.delete(this),e.EventTarget.removeEventListeners(this.#c),this.globalObjectCleared(),this.#S.dispose()}}const ue=new Set;var le=Object.freeze({__proto__:null,DefaultScriptMapping:ce});const de={liveEditFailed:"`LiveEdit` failed: {PH1}",liveEditCompileFailed:"`LiveEdit` compile failed: {PH1}"},ge=n.i18n.registerUIStrings("models/bindings/ResourceScriptMapping.ts",de),pe=n.i18n.getLocalizedString.bind(void 0,ge);class he{debuggerModel;#V;debuggerWorkspaceBinding;#Q;#u;#$;#c;constructor(e,t,o){this.debuggerModel=e,this.#V=t,this.debuggerWorkspaceBinding=o,this.#Q=new Map,this.#u=new Map,this.#$=new Map;const s=e.runtimeModel();this.#c=[this.debuggerModel.addEventListener(r.DebuggerModel.Events.ParsedScriptSource,(e=>this.addScript(e.data)),this),this.debuggerModel.addEventListener(r.DebuggerModel.Events.GlobalObjectCleared,this.globalObjectCleared,this),s.addEventListener(r.RuntimeModel.Events.ExecutionContextDestroyed,this.executionContextDestroyed,this),s.target().targetManager().addEventListener(r.TargetManager.Events.InspectedURLChanged,this.inspectedURLChanged,this)]}project(e){const t=(e.isContentScript()?"js:extensions:":"js::")+this.debuggerModel.target().id()+":"+e.frameId;let o=this.#u.get(t);if(!o){const r=e.isContentScript()?i.Workspace.projectTypes.ContentScripts:i.Workspace.projectTypes.Network;o=new d(this.#V,t,r,"",!1),T.setTargetForProject(o,this.debuggerModel.target()),this.#u.set(t,o)}return o}uiSourceCodeForScript(e){return this.#$.get(e)??null}rawLocationToUILocation(e){const t=e.script();if(!t)return null;const o=this.#$.get(t);if(!o)return null;const r=this.#Q.get(o);if(!r)return null;if(r.hasDivergedFromVM()&&!r.isMergingToVM()||r.isDivergingFromVM())return null;if(r.script!==t)return null;const{lineNumber:s,columnNumber:i=0}=e;return o.uiLocation(s,i)}uiLocationToRawLocations(e,t,o){const r=this.#Q.get(e);if(!r)return[];const{script:s}=r;return s?[this.debuggerModel.createRawLocation(s,t,o)]:[]}uiLocationRangeToRawLocationRanges(e,{startLine:t,startColumn:o,endLine:r,endColumn:s}){const i=this.#Q.get(e);if(!i)return null;const{script:n}=i;if(!n)return null;return[{start:this.debuggerModel.createRawLocation(n,t,o),end:this.debuggerModel.createRawLocation(n,r,s)}]}inspectedURLChanged(e){for(let t=this.debuggerModel.target();t!==e.data;t=t.parentTarget())if(null===t)return;for(const e of Array.from(this.#$.keys()))this.removeScripts([e]),this.addScript(e)}addScript(t){if(t.isLiveEdit()||t.isBreakpointCondition)return;let o=t.sourceURL;if(!o)return;if(t.hasSourceURL)o=r.SourceMapManager.SourceMapManager.resolveRelativeSourceURL(t.debuggerModel.target(),o);else{if(t.isInlineScript())return;if(t.isContentScript()){if(!new e.ParsedURL.ParsedURL(o).isValid)return}}const s=this.project(t),i=s.uiSourceCodeForURL(o);if(i){const e=this.#Q.get(i);e&&e.script&&this.removeScripts([e.script])}const n=t.originalContentProvider(),a=s.createUISourceCode(o,n.contentType());T.setInitialFrameAttribution(a,t.frameId);const c=x(this.debuggerModel.target(),t.frameId,o),u=new me(this,a,t);this.#Q.set(a,u),this.#$.set(t,a);const l=t.isWasm()?"application/wasm":"text/javascript";s.addUISourceCodeWithProvider(a,n,c,l),this.debuggerWorkspaceBinding.updateLocations(t)}scriptFile(e){return this.#Q.get(e)||null}removeScripts(e){const o=new t.MapUtilities.Multimap;for(const t of e){const e=this.#$.get(t);if(!e)continue;const r=this.#Q.get(e);r&&r.dispose(),this.#Q.delete(e),this.#$.delete(t),o.set(e.project(),e),this.debuggerWorkspaceBinding.updateLocations(t)}for(const e of o.keysArray()){const t=o.get(e);let r=!0;for(const o of e.uiSourceCodes())if(!t.has(o)){r=!1;break}r?(this.#u.delete(e.id()),e.removeProject()):t.forEach((t=>e.removeUISourceCode(t.url())))}}executionContextDestroyed(e){const t=e.data;this.removeScripts(this.debuggerModel.scriptsForExecutionContext(t))}globalObjectCleared(){const e=Array.from(this.#$.keys());this.removeScripts(e)}resetForTest(){this.globalObjectCleared()}dispose(){e.EventTarget.removeEventListeners(this.#c),this.globalObjectCleared()}}class me extends e.ObjectWrapper.ObjectWrapper{#X;#Y;#Z;#ee;#te;#oe;#re;#se=new e.Mutex.Mutex;constructor(e,t,o){super(),this.#X=e,this.#Y=t,this.#Y.contentType().isScript()&&(this.#Z=o),this.#Y.addEventListener(i.UISourceCode.Events.WorkingCopyChanged,this.workingCopyChanged,this),this.#Y.addEventListener(i.UISourceCode.Events.WorkingCopyCommitted,this.workingCopyCommitted,this)}isDiverged(){if(this.#Y.isDirty())return!0;if(!this.#Z)return!1;if(void 0===this.#ee||null===this.#ee)return!1;const e=this.#Y.workingCopy();if(!e)return!1;if(!e.startsWith(this.#ee.trimEnd()))return!0;const t=this.#Y.workingCopy().substr(this.#ee.length);return Boolean(t.length)&&!t.match(r.Script.sourceURLRegex)}workingCopyChanged(){this.update()}workingCopyCommitted(){if(this.#Y.project().canSetFileContent())return;if(!this.#Z)return;const e=this.#Y.workingCopy();this.#Z.editSource(e).then((({status:t,exceptionDetails:o})=>{this.scriptSourceWasSet(e,t,o)}))}async scriptSourceWasSet(t,o,r){if("Ok"===o&&(this.#ee=t),await this.update(),"Ok"===o)return;if(!r)return void e.Console.Console.instance().addMessage(pe(de.liveEditFailed,{PH1:function(e){switch(e){case"BlockedByActiveFunction":return"Functions that are on the stack (currently being executed) can not be edited";case"BlockedByActiveGenerator":return"Async functions/generators that are active can not be edited";case"BlockedByTopLevelEsModuleChange":return"The top-level of ES modules can not be edited";case"CompileError":case"Ok":throw new Error("Compile errors and Ok status must not be reported on the console")}}(o)}),e.Console.MessageLevel.Warning);const s=pe(de.liveEditCompileFailed,{PH1:r.text});this.#Y.addLineMessage(i.UISourceCode.Message.Level.Error,s,r.lineNumber,r.columnNumber)}async update(){const e=await this.#se.acquire();this.isDiverged()&&!this.#oe?await this.divergeFromVM():!this.isDiverged()&&this.#oe&&await this.mergeToVM(),e()}async divergeFromVM(){this.#Z&&(this.#te=!0,await this.#X.debuggerWorkspaceBinding.updateLocations(this.#Z),this.#te=void 0,this.#oe=!0,this.dispatchEventToListeners("DidDivergeFromVM"))}async mergeToVM(){this.#Z&&(this.#oe=void 0,this.#re=!0,await this.#X.debuggerWorkspaceBinding.updateLocations(this.#Z),this.#re=void 0,this.dispatchEventToListeners("DidMergeToVM"))}hasDivergedFromVM(){return Boolean(this.#oe)}isDivergingFromVM(){return Boolean(this.#te)}isMergingToVM(){return Boolean(this.#re)}checkMapping(){this.#Z&&void 0===this.#ee?this.#Z.requestContent().then((e=>{this.#ee=e.content,this.update().then((()=>this.mappingCheckedForTest()))})):this.mappingCheckedForTest()}mappingCheckedForTest(){}dispose(){this.#Y.removeEventListener(i.UISourceCode.Events.WorkingCopyChanged,this.workingCopyChanged,this),this.#Y.removeEventListener(i.UISourceCode.Events.WorkingCopyCommitted,this.workingCopyCommitted,this)}addSourceMapURL(e){this.#Z&&this.#Z.debuggerModel.setSourceMapURL(this.#Z,e)}addDebugInfoURL(e){if(!this.#Z)return;const{pluginManager:t}=Me.instance();t&&t.setDebugInfoURL(this.#Z,e)}hasSourceMapURL(){return void 0!==this.#Z&&Boolean(this.#Z.sourceMapURL)}async missingSymbolFiles(){if(!this.#Z)return null;const{pluginManager:e}=this.#X.debuggerWorkspaceBinding;if(!e)return null;const t=await e.getSourcesForScript(this.#Z);return t&&"missingSymbolFiles"in t?t.missingSymbolFiles:null}get script(){return this.#Z||null}get uiSourceCode(){return this.#Y}}var Se=Object.freeze({__proto__:null,ResourceScriptMapping:he,ResourceScriptFile:me});let Le;class Me{resourceMapping;#ie;#J;#F;pluginManager;#ne;constructor(e,t){this.resourceMapping=e,this.#ie=[],this.#J=new Map,t.addModelListener(r.DebuggerModel.DebuggerModel,r.DebuggerModel.Events.GlobalObjectCleared,this.globalObjectCleared,this),t.addModelListener(r.DebuggerModel.DebuggerModel,r.DebuggerModel.Events.DebuggerResumed,this.debuggerResumed,this),t.observeModels(r.DebuggerModel.DebuggerModel,this),this.#ne=t,this.#F=new Set,this.pluginManager=a.Runtime.experiments.isEnabled("wasmDWARFDebugging")?new ie(t,e.workspace,this):null}initPluginManagerForTest(){return a.Runtime.experiments.isEnabled("wasmDWARFDebugging")?this.pluginManager||(this.pluginManager=new ie(this.#ne,this.resourceMapping.workspace,this)):this.pluginManager=null,this.pluginManager}static instance(e={forceNew:null,resourceMapping:null,targetManager:null}){const{forceNew:t,resourceMapping:o,targetManager:r}=e;if(!Le||t){if(!o||!r)throw new Error(`Unable to create DebuggerWorkspaceBinding: resourceMapping and targetManager must be provided: ${(new Error).stack}`);Le=new Me(o,r)}return Le}static removeInstance(){Le=void 0}addSourceMapping(e){this.#ie.push(e)}removeSourceMapping(e){const t=this.#ie.indexOf(e);-1!==t&&this.#ie.splice(t,1)}async computeAutoStepRanges(e,t){function o(e,t){const{start:o,end:r}=t;return o.scriptId===e.scriptId&&(!(e.lineNumber<o.lineNumber||e.lineNumber>r.lineNumber)&&(!(e.lineNumber===o.lineNumber&&e.columnNumber<o.columnNumber)&&!(e.lineNumber===r.lineNumber&&e.columnNumber>=r.columnNumber)))}const s=t.location();if(!s)return[];const i=this.pluginManager;let n=[];if(i){if(e===r.DebuggerModel.StepMode.StepOut)return await i.getInlinedFunctionRanges(s);const t=await i.rawLocationToUILocation(s);if(t)return n=await i.uiLocationToRawLocationRanges(t.uiSourceCode,t.lineNumber,t.columnNumber)||[],n=n.filter((e=>o(s,e))),e===r.DebuggerModel.StepMode.StepOver&&(n=n.concat(await i.getInlinedCalleesRanges(s))),n}const a=this.#J.get(s.debuggerModel)?.compilerMapping;return a?e===r.DebuggerModel.StepMode.StepOut?[]:(n=a.getLocationRangesForSameSourceLocation(s),n=n.filter((e=>o(s,e))),n):[]}modelAdded(e){e.setBeforePausedCallback(this.shouldPause.bind(this)),this.#J.set(e,new fe(e,this)),e.setComputeAutoStepRangesCallback(this.computeAutoStepRanges.bind(this))}modelRemoved(e){e.setComputeAutoStepRangesCallback(null);const t=this.#J.get(e);t&&(t.dispose(),this.#J.delete(e))}async pendingLiveLocationChangesPromise(){await Promise.all(this.#F)}recordLiveLocationChange(e){e.then((()=>{this.#F.delete(e)})),this.#F.add(e)}async updateLocations(e){const t=this.#J.get(e.debuggerModel);if(t){const o=t.updateLocations(e);this.recordLiveLocationChange(o),await o}}async createLiveLocation(e,t,o){const r=this.#J.get(e.debuggerModel);if(!r)return null;const s=r.createLiveLocation(e,t,o);return this.recordLiveLocationChange(s),s}async createStackTraceTopFrameLiveLocation(e,t,o){console.assert(e.length>0);const r=Ce.createStackTraceTopFrameLocation(e,this,t,o);return this.recordLiveLocationChange(r),r}async createCallFrameLiveLocation(e,t,o){if(!e.script())return null;const r=e.debuggerModel,s=this.createLiveLocation(e,t,o);this.recordLiveLocationChange(s);const i=await s;return i?(this.registerCallFrameLiveLocation(r,i),i):null}async rawLocationToUILocation(e){for(const t of this.#ie){const o=t.rawLocationToUILocation(e);if(o)return o}if(this.pluginManager){const t=await this.pluginManager.rawLocationToUILocation(e);if(t)return t}const t=this.#J.get(e.debuggerModel);return t?t.rawLocationToUILocation(e):null}uiSourceCodeForSourceMapSourceURL(e,t,o){const r=this.#J.get(e);return r?r.compilerMapping.uiSourceCodeForURL(t,o):null}async uiSourceCodeForSourceMapSourceURLPromise(e,t,o){return this.uiSourceCodeForSourceMapSourceURL(e,t,o)||this.waitForUISourceCodeAdded(t,e.target())}async uiSourceCodeForDebuggerLanguagePluginSourceURLPromise(e,t){if(this.pluginManager){return this.pluginManager.uiSourceCodeForURL(e,t)||this.waitForUISourceCodeAdded(t,e.target())}return null}uiSourceCodeForScript(e){const t=this.#J.get(e.debuggerModel);return t?t.uiSourceCodeForScript(e):null}waitForUISourceCodeAdded(e,t){return new Promise((o=>{const r=i.Workspace.WorkspaceImpl.instance(),s=r.addEventListener(i.Workspace.Events.UISourceCodeAdded,(n=>{const a=n.data;a.url()===e&&T.targetForUISourceCode(a)===t&&(r.removeEventListener(i.Workspace.Events.UISourceCodeAdded,s.listener),o(a))}))}))}async uiLocationToRawLocations(e,t,o){for(const r of this.#ie){const s=r.uiLocationToRawLocations(e,t,o);if(s.length)return s}const r=await(this.pluginManager?.uiLocationToRawLocations(e,t,o));if(r)return r;for(const r of this.#J.values()){const s=r.uiLocationToRawLocations(e,t,o);if(s.length)return s}return[]}async uiLocationRangeToRawLocationRanges(e,t){for(const o of this.#ie){const r=o.uiLocationRangeToRawLocationRanges(e,t);if(r)return r}if(null!==this.pluginManager){const o=await this.pluginManager.uiLocationRangeToRawLocationRanges(e,t);if(o)return o}for(const o of this.#J.values()){const r=o.uiLocationRangeToRawLocationRanges(e,t);if(r)return r}return[]}uiLocationToRawLocationsForUnformattedJavaScript(e,t,o){console.assert(e.contentType().isScript());const r=[];for(const s of this.#J.values())r.push(...s.uiLocationToRawLocations(e,t,o));return r}async normalizeUILocation(e){const t=await this.uiLocationToRawLocations(e.uiSourceCode,e.lineNumber,e.columnNumber);for(const e of t){const t=await this.rawLocationToUILocation(e);if(t)return t}return e}async getMappedLines(e){for(const t of this.#J.values()){const o=t.getMappedLines(e);if(null!==o)return o}const{pluginManager:t}=this;return t?await t.getMappedLines(e):null}scriptFile(e,t){const o=this.#J.get(t);return o?o.getResourceScriptMapping().scriptFile(e):null}scriptsForUISourceCode(e){const t=new Set;this.pluginManager&&this.pluginManager.scriptsForUISourceCode(e).forEach((e=>t.add(e)));for(const o of this.#J.values()){const r=o.getResourceScriptMapping().scriptFile(e);r&&r.script&&t.add(r.script),o.compilerMapping.scriptsForUISourceCode(e).forEach((e=>t.add(e)))}return[...t]}supportsConditionalBreakpoints(e){if(!this.pluginManager)return!0;return this.pluginManager.scriptsForUISourceCode(e).every((e=>e.isJavaScript()))}globalObjectCleared(e){this.reset(e.data)}reset(e){const t=this.#J.get(e);if(t){for(const e of t.callFrameLocations.values())this.removeLiveLocation(e);t.callFrameLocations.clear()}}resetForTest(e){const t=e.model(r.DebuggerModel.DebuggerModel),o=this.#J.get(t);o&&o.getResourceScriptMapping().resetForTest()}registerCallFrameLiveLocation(e,t){const o=this.#J.get(e);if(o){o.callFrameLocations.add(t)}}removeLiveLocation(e){const t=this.#J.get(e.rawLocation.debuggerModel);t&&t.disposeLocation(e)}debuggerResumed(e){this.reset(e.data)}async shouldPause(t,o){const{callFrames:[r]}=t;if(!r)return!1;const s=r.functionLocation();if(!(o&&"step"===t.reason&&s&&this.pluginManager&&r.script.isWasm()&&e.Settings.moduleSetting("wasmAutoStepping").get()&&this.pluginManager.hasPluginForScript(r.script)))return!0;return!!await this.pluginManager.rawLocationToUILocation(r.location())||(o.script()!==s.script()||o.columnNumber!==s.columnNumber||o.lineNumber!==s.lineNumber)}}class fe{#ae;#o;callFrameLocations;#ce;#R;#X;compilerMapping;#m;constructor(e,o){this.#ae=e,this.#o=o,this.callFrameLocations=new Set;const{workspace:r}=o.resourceMapping;this.#ce=new ce(e,r,o),this.#R=o.resourceMapping,this.#X=new he(e,r,o),this.compilerMapping=new y(e,r,o),this.#m=new t.MapUtilities.Multimap}async createLiveLocation(e,t,o){console.assert(""!==e.scriptId);const r=e.scriptId,s=new be(r,e,this.#o,t,o);return this.#m.set(r,s),await s.update(),s}disposeLocation(e){this.#m.delete(e.scriptId,e)}async updateLocations(e){const t=[];for(const o of this.#m.get(e.scriptId))t.push(o.update());await Promise.all(t)}rawLocationToUILocation(e){let t=this.compilerMapping.rawLocationToUILocation(e);return t=t||this.#X.rawLocationToUILocation(e),t=t||this.#R.jsLocationToUILocation(e),t=t||this.#ce.rawLocationToUILocation(e),t}uiSourceCodeForScript(e){let t=null;return t=t||this.#X.uiSourceCodeForScript(e),t=t||this.#R.uiSourceCodeForScript(e),t=t||this.#ce.uiSourceCodeForScript(e),t}uiLocationToRawLocations(e,t,o=0){let r=this.compilerMapping.uiLocationToRawLocations(e,t,o);return r=r.length?r:this.#X.uiLocationToRawLocations(e,t,o),r=r.length?r:this.#R.uiLocationToJSLocations(e,t,o),r=r.length?r:this.#ce.uiLocationToRawLocations(e,t,o),r}uiLocationRangeToRawLocationRanges(e,t){let o=this.compilerMapping.uiLocationRangeToRawLocationRanges(e,t);return o??=this.#X.uiLocationRangeToRawLocationRanges(e,t),o??=this.#R.uiLocationRangeToJSLocationRanges(e,t),o??=this.#ce.uiLocationRangeToRawLocationRanges(e,t),o}getMappedLines(e){return this.compilerMapping.getMappedLines(e)}dispose(){this.#ae.setBeforePausedCallback(null),this.compilerMapping.dispose(),this.#X.dispose(),this.#ce.dispose()}getResourceScriptMapping(){return this.#X}}class be extends U{scriptId;rawLocation;#ue;constructor(e,t,o,r,s){super(r,s),this.scriptId=e,this.rawLocation=t,this.#ue=o}async uiLocation(){const e=this.rawLocation;return this.#ue.rawLocationToUILocation(e)}dispose(){super.dispose(),this.#ue.removeLiveLocation(this)}async isIgnoreListed(){const e=await this.uiLocation();return!!e&&L.instance().isUserOrSourceMapIgnoreListedUISourceCode(e.uiSourceCode)}}class Ce extends U{#le;#de;#m;constructor(e,t){super(e,t),this.#le=!0,this.#de=null,this.#m=null}static async createStackTraceTopFrameLocation(e,t,o,r){const s=new Ce(o,r),i=e.map((e=>t.createLiveLocation(e,s.scheduleUpdate.bind(s),r)));return s.#m=(await Promise.all(i)).filter((e=>Boolean(e))),await s.updateLocation(),s}async uiLocation(){return this.#de?this.#de.uiLocation():null}async isIgnoreListed(){return!!this.#de&&this.#de.isIgnoreListed()}dispose(){if(super.dispose(),this.#m)for(const e of this.#m)e.dispose();this.#m=null,this.#de=null}async scheduleUpdate(){this.#le||(this.#le=!0,queueMicrotask((()=>{this.updateLocation()})))}async updateLocation(){if(this.#le=!1,this.#m&&0!==this.#m.length){this.#de=this.#m[0];for(const e of this.#m)if(!await e.isIgnoreListed()){this.#de=e;break}this.update()}}}var Ie=Object.freeze({__proto__:null,DebuggerWorkspaceBinding:Me,Location:be});class ve{#ge;#pe;#he;#me;#Se;#Le;#Me;#fe;#be;#Ce;#Ie;#ve;constructor(e,t,o){this.#ge=e,this.#pe=e.size,this.#he=0,this.#Se=t,this.#Le=o,this.#Me=new TextDecoder,this.#fe=!1,this.#be=null,this.#me=null}async read(e){if(this.#Le&&this.#Le(this),this.#ge?.type.endsWith("gzip")){const e=this.#ge.stream(),t=this.decompressStream(e);this.#me=t.getReader()}else this.#ve=new FileReader,this.#ve.onload=this.onChunkLoaded.bind(this),this.#ve.onerror=this.onError.bind(this);return this.#Ie=e,this.loadChunk(),new Promise((e=>{this.#Ce=e}))}cancel(){this.#fe=!0}loadedSize(){return this.#he}fileSize(){return this.#pe}fileName(){return this.#ge?this.#ge.name:""}error(){return this.#be}decompressStream(e){const t=new DecompressionStream("gzip");return e.pipeThrough(t)}onChunkLoaded(e){if(this.#fe)return;if(e.target.readyState!==FileReader.DONE)return;if(!this.#ve)return;const t=this.#ve.result;this.#he+=t.byteLength;const o=this.#he===this.#pe;this.decodeChunkBuffer(t,o)}async decodeChunkBuffer(e,t){if(!this.#Ie)return;const o=this.#Me.decode(e,{stream:!t});await this.#Ie.write(o),this.#fe||(this.#Le&&this.#Le(this),t?this.finishRead():this.loadChunk())}async finishRead(){this.#Ie&&(this.#ge=null,this.#ve=null,await this.#Ie.close(),this.#Ce(!this.#be))}async loadChunk(){if(this.#Ie&&this.#ge){if(this.#me){const{value:e,done:t}=await this.#me.read();if(t||!e)return this.finishRead();this.decodeChunkBuffer(e.buffer,!1)}if(this.#ve){const e=this.#he,t=Math.min(this.#pe,e+this.#Se),o=this.#ge.slice(e,t);this.#ve.readAsArrayBuffer(o)}}}onError(e){const t=e.target;this.#be=t.error,this.#Ce(!1)}}var we=Object.freeze({__proto__:null,ChunkedFileReader:ve,FileOutputStream:class{#we;#Te;#Re;constructor(){this.#we=[]}async open(e){this.#Re=!1,this.#we=[],this.#Te=e;const t=await i.FileManager.FileManager.instance().save(this.#Te,"",!0);return t&&i.FileManager.FileManager.instance().addEventListener(i.FileManager.Events.AppendedToURL,this.onAppendDone,this),Boolean(t)}write(e){return new Promise((t=>{this.#we.push(t),i.FileManager.FileManager.instance().append(this.#Te,e)}))}async close(){this.#Re=!0,this.#we.length||(i.FileManager.FileManager.instance().removeEventListener(i.FileManager.Events.AppendedToURL,this.onAppendDone,this),i.FileManager.FileManager.instance().close(this.#Te))}onAppendDone(e){if(e.data!==this.#Te)return;const t=this.#we.shift();t&&t(),this.#we.length||this.#Re&&(i.FileManager.FileManager.instance().removeEventListener(i.FileManager.Events.AppendedToURL,this.onAppendDone,this),i.FileManager.FileManager.instance().close(this.#Te))}}});class Te{#ye=new WeakMap;constructor(){r.TargetManager.TargetManager.instance().observeModels(r.DebuggerModel.DebuggerModel,this),r.TargetManager.TargetManager.instance().observeModels(r.CSSModel.CSSModel,this)}modelAdded(e){const t=e.target(),o=this.#ye.get(t)??new Re;e instanceof r.DebuggerModel.DebuggerModel?o.setDebuggerModel(e):o.setCSSModel(e),this.#ye.set(t,o)}modelRemoved(e){const t=e.target();this.#ye.get(t)?.clear()}addMessage(e,t,o){this.#ye.get(o)?.addMessage(e,t)}clear(){for(const e of r.TargetManager.TargetManager.instance().targets()){this.#ye.get(e)?.clear()}}}class Re{#ae;#b;#Fe=new Map;#p;constructor(){this.#p=new P,i.Workspace.WorkspaceImpl.instance().addEventListener(i.Workspace.Events.UISourceCodeAdded,this.#Ue.bind(this))}setDebuggerModel(e){if(this.#ae)throw new Error("Cannot set DebuggerModel twice");this.#ae=e,e.addEventListener(r.DebuggerModel.Events.ParsedScriptSource,(e=>{queueMicrotask((()=>{this.#Pe(e)}))})),e.addEventListener(r.DebuggerModel.Events.GlobalObjectCleared,this.#ke,this)}setCSSModel(e){if(this.#b)throw new Error("Cannot set CSSModel twice");this.#b=e,e.addEventListener(r.CSSModel.Events.StyleSheetAdded,(e=>queueMicrotask((()=>this.#je(e)))))}async addMessage(e,t){const o=new Fe(e,this.#p),r=this.#De(t)??this.#Ee(t)??this.#Ne(t);if(r&&await o.updateLocationSource(r),t.url){let e=this.#Fe.get(t.url);e||(e=[],this.#Fe.set(t.url,e)),e.push({source:t,presentation:o})}}#Ne(e){if(!e.url)return null;const t=i.Workspace.WorkspaceImpl.instance().uiSourceCodeForURL(e.url);return t?new i.UISourceCode.UILocation(t,e.line,e.column):null}#Ee(e){if(!this.#b||!e.url)return null;return this.#b.createRawLocationsByURL(e.url,e.line,e.column)[0]??null}#De(e){if(!this.#ae)return null;if(e.scriptId)return this.#ae.createRawLocationByScriptId(e.scriptId,e.line,e.column);const t=e.stackTrace&&e.stackTrace.callFrames?e.stackTrace.callFrames[0]:null;return t?this.#ae.createRawLocationByScriptId(t.scriptId,t.lineNumber,t.columnNumber):e.url?this.#ae.createRawLocationByURL(e.url,e.line,e.column):null}#Pe(e){const t=e.data,o=this.#Fe.get(t.sourceURL),r=[];for(const{presentation:e,source:s}of o??[]){const o=this.#De(s);o&&t.scriptId===o.scriptId&&r.push(e.updateLocationSource(o))}Promise.all(r).then(this.parsedScriptSourceForTest.bind(this))}parsedScriptSourceForTest(){}#Ue(e){const t=e.data,o=this.#Fe.get(t.url()),r=[];for(const{presentation:e,source:s}of o??[])r.push(e.updateLocationSource(new i.UISourceCode.UILocation(t,s.line,s.column)));Promise.all(r).then(this.uiSourceCodeAddedForTest.bind(this))}uiSourceCodeAddedForTest(){}#je(e){const t=e.data,o=this.#Fe.get(t.sourceURL),s=[];for(const{source:e,presentation:i}of o??[])t.containsLocation(e.line,e.column)&&s.push(i.updateLocationSource(new r.CSSModel.CSSLocation(t,e.line,e.column)));Promise.all(s).then(this.styleSheetAddedForTest.bind(this))}styleSheetAddedForTest(){}clear(){this.#ke()}#ke(){const e=Array.from(this.#Fe.values()).flat();for(const{presentation:t}of e)t.dispose();this.#Fe.clear(),this.#p.disposeAll()}}class ye extends U{#Ne;constructor(e,t,o){super(t,o),this.#Ne=e}async isIgnoreListed(){return!1}async uiLocation(){return this.#Ne}}class Fe{#Ae;#xe;#p;#Oe;constructor(e,t){this.#Oe=e,this.#p=t}async updateLocationSource(e){e instanceof r.DebuggerModel.Location?await Me.instance().createLiveLocation(e,this.#We.bind(this),this.#p):e instanceof r.CSSModel.CSSLocation?await q.instance().createLiveLocation(e,this.#We.bind(this),this.#p):e instanceof i.UISourceCode.UILocation&&(this.#xe||(this.#xe=new ye(e,this.#We.bind(this),this.#p),await this.#xe.update()))}async#We(e){this.#Ae&&this.#Ae.removeMessage(this.#Oe),e!==this.#xe&&(this.#Ae?.removeMessage(this.#Oe),this.#xe?.dispose(),this.#xe=e);const t=await e.uiLocation();t&&(this.#Oe.range=s.TextRange.TextRange.createFromLocation(t.lineNumber,t.columnNumber||0),this.#Ae=t.uiSourceCode,this.#Ae.addMessage(this.#Oe))}dispose(){this.#Ae?.removeMessage(this.#Oe),this.#xe?.dispose()}}var Ue=Object.freeze({__proto__:null,PresentationSourceFrameMessageManager:Te,PresentationConsoleMessageManager:class{#Be=new Te;constructor(){r.TargetManager.TargetManager.instance().addModelListener(r.ConsoleModel.ConsoleModel,r.ConsoleModel.Events.MessageAdded,(e=>this.consoleMessageAdded(e.data))),r.ConsoleModel.ConsoleModel.allMessagesUnordered().forEach(this.consoleMessageAdded,this),r.TargetManager.TargetManager.instance().addModelListener(r.ConsoleModel.ConsoleModel,r.ConsoleModel.Events.ConsoleCleared,(()=>this.#Be.clear()))}consoleMessageAdded(e){const t=e.runtimeModel();if(!e.isErrorOrWarning()||!e.runtimeModel()||"violation"===e.source||!t)return;const o="error"===e.level?i.UISourceCode.Message.Level.Error:i.UISourceCode.Message.Level.Warning;this.#Be.addMessage(new i.UISourceCode.Message(o,e.messageText),e,t.target())}},PresentationSourceFrameMessageHelper:Re,PresentationSourceFrameMessage:Fe});const Pe=new WeakMap,ke=new WeakMap,je=new WeakSet;function De(e){return new s.TextRange.TextRange(e.lineOffset,e.columnOffset,e.endLine,e.endColumn)}function Ee(e){return new s.TextRange.TextRange(e.startLine,e.startColumn,e.endLine,e.endColumn)}class Ne{project;#L;#b;#c;constructor(e,t){const o=t.target();this.project=new d(e,"resources:"+o.id(),i.Workspace.projectTypes.Network,"",!1),T.setTargetForProject(this.project,o),this.#L=new Map;const s=o.model(r.CSSModel.CSSModel);console.assert(Boolean(s)),this.#b=s;for(const e of t.frames())for(const t of e.getResourcesMap().values())this.addResource(t);this.#c=[t.addEventListener(r.ResourceTreeModel.Events.ResourceAdded,this.resourceAdded,this),t.addEventListener(r.ResourceTreeModel.Events.FrameWillNavigate,this.frameWillNavigate,this),t.addEventListener(r.ResourceTreeModel.Events.FrameDetached,this.frameDetached,this),this.#b.addEventListener(r.CSSModel.Events.StyleSheetChanged,(e=>{this.styleSheetChanged(e)}),this)]}async styleSheetChanged(e){const t=this.#b.styleSheetHeaderForId(e.data.styleSheetId);if(!t||!t.isInline||t.isInline&&t.isMutable)return;const o=this.#L.get(t.resourceURL());o&&await o.styleSheetChanged(t,e.data.edit||null)}acceptsResource(t){const o=t.resourceType();return(o===e.ResourceType.resourceTypes.Image||o===e.ResourceType.resourceTypes.Font||o===e.ResourceType.resourceTypes.Document||o===e.ResourceType.resourceTypes.Manifest)&&(!(o===e.ResourceType.resourceTypes.Image&&t.mimeType&&!t.mimeType.startsWith("image"))&&(!(o===e.ResourceType.resourceTypes.Font&&t.mimeType&&!t.mimeType.includes("font"))&&(o!==e.ResourceType.resourceTypes.Image&&o!==e.ResourceType.resourceTypes.Font||!t.contentURL().startsWith("data:"))))}resourceAdded(e){this.addResource(e.data)}addResource(e){if(!this.acceptsResource(e))return;let t=this.#L.get(e.url);t?t.addResource(e):(t=new Ae(this.project,e),this.#L.set(e.url,t))}removeFrameResources(e){for(const t of e.resources()){if(!this.acceptsResource(t))continue;const e=this.#L.get(t.url);e&&(1===e.resources.size?(e.dispose(),this.#L.delete(t.url)):e.removeResource(t))}}frameWillNavigate(e){this.removeFrameResources(e.data)}frameDetached(e){this.removeFrameResources(e.data.frame)}resetForTest(){for(const e of this.#L.values())e.dispose();this.#L.clear()}dispose(){e.EventTarget.removeEventListeners(this.#c);for(const e of this.#L.values())e.dispose();this.#L.clear(),this.project.removeProject()}getProject(){return this.project}}class Ae{resources;#S;#Ae;#He;constructor(e,t){this.resources=new Set([t]),this.#S=e,this.#Ae=this.#S.createUISourceCode(t.url,t.contentType()),je.add(this.#Ae),t.frameId&&T.setInitialFrameAttribution(this.#Ae,t.frameId),this.#S.addUISourceCodeWithProvider(this.#Ae,this,O(t),t.mimeType),this.#He=[],Promise.all([...this.inlineScripts().map((e=>Me.instance().updateLocations(e))),...this.inlineStyles().map((e=>q.instance().updateLocations(e)))])}inlineStyles(){const e=T.targetForUISourceCode(this.#Ae),t=[];if(!e)return t;const o=e.model(r.CSSModel.CSSModel);if(o)for(const e of o.getStyleSheetIdsForURL(this.#Ae.url())){const r=o.styleSheetHeaderForId(e);r&&t.push(r)}return t}inlineScripts(){const e=T.targetForUISourceCode(this.#Ae);if(!e)return[];const t=e.model(r.DebuggerModel.DebuggerModel);return t?t.scripts().filter((e=>e.embedderName()===this.#Ae.url())):[]}async styleSheetChanged(e,t){if(this.#He.push({stylesheet:e,edit:t}),this.#He.length>1)return;const{content:o}=await this.#Ae.requestContent();null!==o&&await this.innerStyleSheetChanged(o),this.#He=[]}async innerStyleSheetChanged(e){const t=this.inlineScripts(),o=this.inlineStyles();let r=new s.Text.Text(e);for(const e of this.#He){const i=e.edit;if(!i)continue;const n=e.stylesheet,a=Pe.get(n)??Ee(n),c=i.oldRange.relativeFrom(a.startLine,a.startColumn),u=i.newRange.relativeFrom(a.startLine,a.startColumn);r=new s.Text.Text(r.replaceRange(c,i.newText));const l=[];for(const e of t){const t=ke.get(e)??De(e);t.follows(c)&&(ke.set(e,t.rebaseAfterTextEdit(c,u)),l.push(Me.instance().updateLocations(e)))}for(const e of o){const t=Pe.get(e)??Ee(e);t.follows(c)&&(Pe.set(e,t.rebaseAfterTextEdit(c,u)),l.push(q.instance().updateLocations(e)))}await Promise.all(l)}this.#Ae.addRevision(r.value())}addResource(e){this.resources.add(e),e.frameId&&T.addFrameAttribution(this.#Ae,e.frameId)}removeResource(e){this.resources.delete(e),e.frameId&&T.removeFrameAttribution(this.#Ae,e.frameId)}dispose(){this.#S.removeUISourceCode(this.#Ae.url()),Promise.all([...this.inlineScripts().map((e=>Me.instance().updateLocations(e))),...this.inlineStyles().map((e=>q.instance().updateLocations(e)))])}firstResource(){return console.assert(this.resources.size>0),this.resources.values().next().value}contentURL(){return this.firstResource().contentURL()}contentType(){return this.firstResource().contentType()}requestContent(){return this.firstResource().requestContent()}searchInContent(e,t,o){return this.firstResource().searchInContent(e,t,o)}}var xe=Object.freeze({__proto__:null,ResourceMapping:class{workspace;#y;constructor(e,t){this.workspace=t,this.#y=new Map,e.observeModels(r.ResourceTreeModel.ResourceTreeModel,this)}modelAdded(e){const t=new Ne(this.workspace,e);this.#y.set(e,t)}modelRemoved(e){const t=this.#y.get(e);t&&(t.dispose(),this.#y.delete(e))}infoForTarget(e){const t=e.model(r.ResourceTreeModel.ResourceTreeModel);return t&&this.#y.get(t)||null}uiSourceCodeForScript(e){const t=this.infoForTarget(e.debuggerModel.target());if(!t)return null;return t.getProject().uiSourceCodeForURL(e.sourceURL)}cssLocationToUILocation(e){const t=e.header();if(!t)return null;const o=this.infoForTarget(e.cssModel().target());if(!o)return null;const r=o.getProject().uiSourceCodeForURL(e.url);if(!r)return null;const s=Pe.get(t)??Ee(t),i=e.lineNumber+s.startLine-t.startLine;let n=e.columnNumber;return e.lineNumber===t.startLine&&(n+=s.startColumn-t.startColumn),r.uiLocation(i,n)}jsLocationToUILocation(e){const t=e.script();if(!t)return null;const o=this.infoForTarget(e.debuggerModel.target());if(!o)return null;const r=t.embedderName();if(!r)return null;const s=o.getProject().uiSourceCodeForURL(r);if(!s)return null;const{startLine:i,startColumn:n}=ke.get(t)??De(t);let{lineNumber:a,columnNumber:c}=e;return a===t.lineOffset&&(c+=n-t.columnOffset),a+=i-t.lineOffset,t.hasSourceURL&&(0===a&&(c+=t.columnOffset),a+=t.lineOffset),s.uiLocation(a,c)}uiLocationToJSLocations(e,t,o){if(!je.has(e))return[];const s=T.targetForUISourceCode(e);if(!s)return[];const i=s.model(r.DebuggerModel.DebuggerModel);if(!i)return[];const n=[];for(const r of i.scripts()){if(r.embedderName()!==e.url())continue;const s=ke.get(r)??De(r);if(!s.containsLocation(t,o))continue;let a=t,c=o;r.hasSourceURL&&(a-=s.startLine,0===a&&(c-=s.startColumn)),n.push(i.createRawLocation(r,a,c))}return n}uiLocationRangeToJSLocationRanges(e,t){if(!je.has(e))return null;const o=T.targetForUISourceCode(e);if(!o)return null;const s=o.model(r.DebuggerModel.DebuggerModel);if(!s)return null;const i=[];for(const o of s.scripts()){if(o.embedderName()!==e.url())continue;const r=(ke.get(o)??De(o)).intersection(t);if(r.isEmpty())continue;let{startLine:n,startColumn:a,endLine:c,endColumn:u}=r;o.hasSourceURL&&(n-=r.startLine,0===n&&(a-=r.startColumn),c-=r.startLine,0===c&&(u-=r.startColumn));const l=s.createRawLocation(o,n,a),d=s.createRawLocation(o,c,u);i.push({start:l,end:d})}return i}getMappedLines(e){if(!je.has(e))return null;const t=T.targetForUISourceCode(e);if(!t)return null;const o=t.model(r.DebuggerModel.DebuggerModel);if(!o)return null;const s=new Set;for(const t of o.scripts()){if(t.embedderName()!==e.url())continue;const{startLine:o,endLine:r}=ke.get(t)??De(t);for(let e=o;e<=r;++e)s.add(e)}return s}uiLocationToCSSLocations(e){if(!je.has(e.uiSourceCode))return[];const t=T.targetForUISourceCode(e.uiSourceCode);if(!t)return[];const o=t.model(r.CSSModel.CSSModel);return o?o.createRawLocationsByURL(e.uiSourceCode.url(),e.lineNumber,e.columnNumber):[]}resetForTest(e){const t=e.model(r.ResourceTreeModel.ResourceTreeModel),o=t?this.#y.get(t):null;o&&o.resetForTest()}}});var Oe=Object.freeze({__proto__:null,TempFile:class{#_e;constructor(){this.#_e=null}write(e){this.#_e&&e.unshift(this.#_e),this.#_e=new Blob(e,{type:"text/plain"})}read(){return this.readRange()}size(){return this.#_e?this.#_e.size:0}async readRange(t,o){if(!this.#_e)return e.Console.Console.instance().error("Attempt to read a temp file that was never written"),"";const r="number"==typeof t||"number"==typeof o?this.#_e.slice(t,o):this.#_e,s=new FileReader;try{await new Promise(((e,t)=>{s.onloadend=e,s.onerror=t,s.readAsText(r)}))}catch(t){e.Console.Console.instance().error("Failed to read from temp file: "+t.message)}return s.result}async copyToOutputStream(e,t){if(!this.#_e)return e.close(),null;const o=new ve(this.#_e,1e7,t);return o.read(e).then((e=>e?null:o.error()))}remove(){this.#_e=null}}});export{G as CSSWorkspaceBinding,F as CompilerScriptMapping,g as ContentProviderBasedProject,ae as DebuggerLanguagePlugins,Ie as DebuggerWorkspaceBinding,le as DefaultScriptMapping,we as FileUtils,f as IgnoreListManager,k as LiveLocation,R as NetworkProject,Ue as PresentationConsoleMessageHelper,xe as ResourceMapping,Se as ResourceScriptMapping,W as ResourceUtils,N as SASSSourceMapping,z as StylesSourceMapping,Oe as TempFile};
